home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / itc / cc1.spur / typecheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-30  |  97.4 KB  |  3,373 lines

  1. /* Build expressions with type checking for C compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* This file is part of the C front end.
  23.    It contains routines to build C expressions given their operands,
  24.    including computing the types of the result, C-specific error checks,
  25.    and some optimization.
  26.  
  27.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  28.    and to process initializations in declarations (since they work
  29.    like a strange sort of assignment).  */
  30.  
  31. #include "config.h"
  32. #include <stdio.h>
  33. #include "tree.h"
  34. #include "c-tree.h"
  35. #include "flags.h"
  36. #include "alloca.h"
  37.  
  38.  
  39.  
  40. static void mark_addressable ();
  41. static tree convert_for_assignment ();
  42. static int compparms ();
  43. int comp_target_types ();
  44. static tree shorten_compare ();
  45. static void binary_op_error ();
  46. static tree pointer_int_sum ();
  47. static tree pointer_diff ();
  48. static tree convert_sequence ();
  49. static tree unary_complex_lvalue ();
  50. static tree process_init_constructor ();
  51. tree digest_init ();
  52. tree truthvalue_conversion ();
  53. void incomplete_type_error ();
  54. void readonly_warning ();
  55.  
  56. /* Return the _TYPE node describing the data type
  57.    of the data which NODE represents as a C expression.
  58.    Arrays and functions are converted to pointers
  59.    just as they are when they appear as C expressions.  */
  60.  
  61. tree
  62. datatype (node)
  63.      tree node;
  64. {
  65.   register tree type = TREE_TYPE (node);
  66.   if (TREE_CODE (type) == ARRAY_TYPE)
  67.     return TYPE_POINTER_TO (TREE_TYPE (type));
  68.   if (TREE_CODE (type) == FUNCTION_TYPE)
  69.     return build_pointer_type (type);
  70.   return type;
  71. }
  72.  
  73. /* Do `exp = require_complete_type (exp);' to make sure exp
  74.    does not have an incomplete type.  (That includes void types.)  */
  75.  
  76. tree
  77. require_complete_type (value)
  78.      tree value;
  79. {
  80.   tree type = TREE_TYPE (value);
  81.  
  82.   /* First, detect a valid value with a complete type.  */
  83.   if (TYPE_SIZE (type) != 0
  84.       && type != void_type_node)
  85.     return value;
  86.  
  87.   incomplete_type_error (value, type);
  88.   return error_mark_node;
  89. }
  90.  
  91. /* Print an error message for invalid use of an incomplete type.
  92.    VALUE is the expression that was used (or 0 if that isn't known)
  93.    and TYPE is the type that was invalid.  */
  94.  
  95. void
  96. incomplete_type_error (value, type)
  97.      tree value;
  98.      tree type;
  99. {
  100.   char *errmsg;
  101.  
  102.   /* Avoid duplicate error message.  */
  103.   if (TREE_CODE (type) == ERROR_MARK)
  104.     return;
  105.  
  106.   if (value != 0 && (TREE_CODE (value) == VAR_DECL
  107.              || TREE_CODE (value) == PARM_DECL))
  108.     error ("`%s' has an incomplete type",
  109.        IDENTIFIER_POINTER (DECL_NAME (value)));
  110.   else
  111.     {
  112.     retry:
  113.       /* We must print an error message.  Be clever about what it says.  */
  114.  
  115.       switch (TREE_CODE (type))
  116.     {
  117.     case RECORD_TYPE:
  118.       errmsg = "invalid use of undefined type `struct %s'";
  119.       break;
  120.  
  121.     case UNION_TYPE:
  122.       errmsg = "invalid use of undefined type `union %s'";
  123.       break;
  124.  
  125.     case ENUMERAL_TYPE:
  126.       errmsg = "invalid use of undefined type `enum %s'";
  127.       break;
  128.  
  129.     case VOID_TYPE:
  130.       error ("invalid use of void expression");
  131.       return;
  132.  
  133.     case ARRAY_TYPE:
  134.       if (TYPE_DOMAIN (type))
  135.         {
  136.           type = TREE_TYPE (type);
  137.           goto retry;
  138.         }
  139.       error ("invalid use of array with unspecified bounds");
  140.       return;
  141.  
  142.     default:
  143.       abort ();
  144.     }
  145.  
  146.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  147.     error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  148.       else
  149.     /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  150.     error ("invalid use of incomplete typedef `%s'",
  151.            IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  152.     }
  153. }
  154.  
  155. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  156.    as well as those of TYPE.  */
  157.  
  158. static tree
  159. qualify_type (type, like)
  160.      tree type, like;
  161. {
  162.   int constflag = TREE_READONLY (type) || TREE_READONLY (like);
  163.   int volflag = TREE_VOLATILE (type) || TREE_VOLATILE (like);
  164.   return build_type_variant (type, constflag, volflag);
  165. }
  166.  
  167. /* Return the common type of two types.
  168.    We assume that comptypes has already been done and returned 1;
  169.    if that isn't so, this may crash.
  170.  
  171.    This is the type for the result of most arithmetic operations
  172.    if the operands have the given two types.
  173.  
  174.    We do not deal with enumeral types here because they have already been
  175.    converted to integer types.  */
  176.  
  177. tree
  178. commontype (t1, t2)
  179.      tree t1, t2;
  180. {
  181.   register enum tree_code form1;
  182.   register enum tree_code form2;
  183.  
  184.   /* Save time if the two types are the same.  */
  185.  
  186.   if (t1 == t2) return t1;
  187.  
  188.   /* Treat an enum type as the unsigned integer type of the same width.  */
  189.  
  190.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  191.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  192.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  193.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  194.  
  195.   form1 = TREE_CODE (t1);
  196.   form2 = TREE_CODE (t2);
  197.  
  198.   switch (form1)
  199.     {
  200.     case INTEGER_TYPE:
  201.     case REAL_TYPE:
  202.       /* If only one is real, use it as the result.  */
  203.  
  204.       if (form1 == REAL_TYPE && form2 != REAL_TYPE)
  205.     return t1;
  206.  
  207.       if (form2 == REAL_TYPE && form1 != REAL_TYPE)
  208.     return t2;
  209.  
  210.       /* Both real or both integers; use the one with greater precision.  */
  211.  
  212.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  213.     return t1;
  214.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  215.     return t2;
  216.  
  217.       /* Same precision.  Prefer longs to ints even when same size.  */
  218.  
  219.       if (t1 == long_unsigned_type_node
  220.       || t2 == long_unsigned_type_node)
  221.     return long_unsigned_type_node;
  222.  
  223.       if (t1 == long_integer_type_node
  224.       || t2 == long_integer_type_node)
  225.     {
  226.       /* But preserve unsignedness from the other type,
  227.          since long cannot hold all the values of an unsigned int.  */
  228.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  229.         return long_unsigned_type_node;
  230.       return long_integer_type_node;
  231.     }
  232.  
  233.       /* Otherwise prefer the unsigned one.  */
  234.  
  235.       if (TREE_UNSIGNED (t1))
  236.     return t1;
  237.       else return t2;
  238.  
  239.     case POINTER_TYPE:
  240. #if 0
  241.       /* For two pointers, do this recursively on the target type,
  242.      and combine the qualifiers of the two types' targets.  */
  243.       {
  244.     tree target = commontype (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  245.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  246.     int constp
  247.       = TREE_READ_ONLY (TREE_TYPE (t1)) || TREE_READ_ONLY (TREE_TYPE (t2));
  248.     int volatilep
  249.       = TREE_VOLATILE (TREE_TYPE (t1)) || TREE_VOLATILE (TREE_TYPE (t2));
  250.     return build_pointer_type (build_type_variant (target, constp, volatilep));
  251.       }
  252. #endif
  253.       return build_pointer_type (commontype (TREE_TYPE (t1), TREE_TYPE (t2)));
  254.  
  255.     case ARRAY_TYPE:
  256.       {
  257.     tree elt = commontype (TREE_TYPE (t1), TREE_TYPE (t2));
  258.     /* Save space: see if the result is identical to one of the args.  */
  259.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  260.       return t1;
  261.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  262.       return t2;
  263.     /* Merge the element types, and have a size if either arg has one.  */
  264.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  265.       }
  266.  
  267.     case FUNCTION_TYPE:
  268.       /* Function types: prefer the one that specified arg types.
  269.      If both do, merge the arg types.  Also merge the return types.  */
  270.       {
  271.     tree valtype = commontype (TREE_TYPE (t1), TREE_TYPE (t2));
  272.     tree p1 = TYPE_ARG_TYPES (t1);
  273.     tree p2 = TYPE_ARG_TYPES (t2);
  274.     int len;
  275.     tree newargs, n;
  276.     int i;
  277.  
  278.     /* Save space: see if the result is identical to one of the args.  */
  279.     if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
  280.       return t1;
  281.     if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
  282.       return t2;
  283.  
  284.     /* Simple way if one arg fails to specify argument types.  */
  285.     if (TYPE_ARG_TYPES (t1) == 0)
  286.       return build_function_type (valtype, TYPE_ARG_TYPES (t2));
  287.     if (TYPE_ARG_TYPES (t2) == 0)
  288.       return build_function_type (valtype, TYPE_ARG_TYPES (t1));
  289.  
  290.     /* If both args specify argument types, we must merge the two
  291.        lists, argument by argument.  */
  292.  
  293.     len = list_length (p1);
  294.     newargs = 0;
  295.  
  296.     for (i = 0; i < len; i++)
  297.       newargs = tree_cons (0, 0, newargs);
  298.  
  299.     n = newargs;
  300.  
  301.     for (; p1;
  302.          p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
  303.       TREE_VALUE (n) = commontype (TREE_VALUE (p1), TREE_VALUE (p2));
  304.  
  305.     return build_function_type (valtype, newargs);
  306.       }
  307.  
  308.     default:
  309.       return t1;
  310.     }
  311.  
  312. }
  313.  
  314. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  315.    or various other operations.  This is what ANSI C speaks of as
  316.    "being the same".  */
  317.  
  318. int
  319. comptypes (type1, type2)
  320.      tree type1, type2;
  321. {
  322.   register tree t1 = type1;
  323.   register tree t2 = type2;
  324.  
  325.   /* Suppress errors caused by previously reported errors */
  326.  
  327.   if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
  328.     return 1;
  329.  
  330.   /* Treat an enum type as the unsigned integer type of the same width.  */
  331.  
  332.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  333.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  334.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  335.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  336.  
  337.   if (t1 == t2)
  338.     return 1;
  339.  
  340.   /* Different classes of types can't be compatible.  */
  341.  
  342.   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
  343.  
  344.   switch (TREE_CODE (t1))
  345.     {
  346.     case POINTER_TYPE:
  347.       return (TREE_TYPE (t1) == TREE_TYPE (t2)
  348.           || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
  349.  
  350.     case FUNCTION_TYPE:
  351.       return ((TREE_TYPE (t1) == TREE_TYPE (t2)
  352.            || comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
  353.           && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)));
  354.  
  355.     case ARRAY_TYPE:
  356.       /* Target types must match.  */
  357.       if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  358.         || comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
  359.     return 0;
  360.       {
  361.     tree d1 = TYPE_DOMAIN (t1);
  362.     tree d2 = TYPE_DOMAIN (t2);
  363.  
  364.     /* Sizes must match unless one is missing or variable.  */
  365.     if (d1 == 0 || d2 == 0 || d1 == d2
  366.         || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  367.         || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  368.         || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  369.         || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  370.       return 1;
  371.  
  372.     return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  373.          == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  374.         && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  375.             == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  376.         && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  377.             == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  378.         && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  379.             == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  380.       }
  381.     }
  382.   return 0;
  383. }
  384.  
  385. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  386.    ignoring their qualifiers.  */
  387.  
  388. int
  389. comp_target_types (ttl, ttr)
  390.      tree ttl, ttr;
  391. {
  392.   return comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  393.             TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  394. }
  395.  
  396. /* Subroutines of `comptypes'.  */
  397.  
  398. /* Return 1 if two parameter type lists PARMS1 and PARMS2
  399.    are equivalent in the sense that functions with those parameter types
  400.    can have equivalent types.
  401.    If either list is empty, we win.
  402.    Otherwise, the two lists must be equivalent, element by element.  */
  403.  
  404. static int
  405. compparms (parms1, parms2)
  406.      tree parms1, parms2;
  407. {
  408.   register tree t1 = parms1, t2 = parms2;
  409.  
  410.   /* An unspecified parmlist matches any specified parmlist
  411.      whose argument types don't need default promotions.  */
  412.  
  413.   if (t1 == 0)
  414.     return compparms1 (t2);
  415.   if (t2 == 0)
  416.     return compparms1 (t1);
  417.  
  418.   while (1)
  419.     {
  420.       if (t1 == 0 && t2 == 0)
  421.     return 1;
  422.       /* If one parmlist is shorter than the other,
  423.      they fail to match.  */
  424.       if (t1 == 0 || t2 == 0)
  425.     return 0;
  426.       if (! comptypes (TREE_VALUE (t1), TREE_VALUE (t2)))
  427.     return 0;
  428.       t1 = TREE_CHAIN (t1);
  429.       t2 = TREE_CHAIN (t2);
  430.     }
  431. }
  432.  
  433. /* Return 1 if PARMS specifies a fixed number of parameters
  434.    and none of their types is affected by default promotions.  */
  435.  
  436. int
  437. compparms1 (parms)
  438.      tree parms;
  439. {
  440.   register tree t;
  441.   for (t = parms; t; t = TREE_CHAIN (t))
  442.     {
  443.       register tree type = TREE_VALUE (t);
  444.  
  445.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  446.     return 0;
  447.  
  448.       if (type == float_type_node)
  449.     return 0;
  450.  
  451.       if (TREE_CODE (type) == INTEGER_TYPE
  452.       && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  453.     return 0;
  454.     }
  455.   return 1;
  456. }
  457.  
  458. /* Return an unsigned type the same as TYPE in other respects.  */
  459.  
  460. tree
  461. unsigned_type (type)
  462.      tree type;
  463. {
  464.   if (type == signed_char_type_node || type == char_type_node)
  465.     return unsigned_char_type_node;
  466.   if (type == integer_type_node)
  467.     return unsigned_type_node;
  468.   if (type == short_integer_type_node)
  469.     return short_unsigned_type_node;
  470.   if (type == long_integer_type_node)
  471.     return long_unsigned_type_node;
  472.   return type;
  473. }
  474.  
  475. /* Return a signed type the same as TYPE in other respects.  */
  476.  
  477. tree
  478. signed_type (type)
  479.      tree type;
  480. {
  481.   if (type == unsigned_char_type_node || type == char_type_node)
  482.     return signed_char_type_node;
  483.   if (type == unsigned_type_node)
  484.     return integer_type_node;
  485.   if (type == short_unsigned_type_node)
  486.     return short_integer_type_node;
  487.   if (type == long_unsigned_type_node)
  488.     return long_integer_type_node;
  489.   return type;
  490. }
  491.  
  492. /* Return a type the same as TYPE except unsigned or
  493.    signed according to UNSIGNEDP.  */
  494.  
  495. tree
  496. signed_or_unsigned_type (unsignedp, type)
  497.      int unsignedp;
  498.      tree type;
  499. {
  500.   if (TREE_CODE (type) != INTEGER_TYPE)
  501.     return type;
  502.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  503.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  504.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  505.     return unsignedp ? unsigned_type_node : integer_type_node;
  506.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  507.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  508.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  509.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  510.   return type;
  511. }
  512.  
  513. /* Return an integer type with BITS bits of precision,
  514.    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
  515.  
  516. tree
  517. type_for_size (bits, unsignedp)
  518.      int bits;
  519.      int unsignedp;
  520. {
  521.   if (bits <= TYPE_PRECISION (signed_char_type_node))
  522.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  523.  
  524.   if (bits <= TYPE_PRECISION (short_integer_type_node))
  525.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  526.  
  527.   if (bits <= TYPE_PRECISION (integer_type_node))
  528.     return unsignedp ? unsigned_type_node : integer_type_node;
  529.  
  530.   if (bits <= TYPE_PRECISION (long_integer_type_node))
  531.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  532.  
  533.   return 0;
  534. }
  535.  
  536. tree
  537. get_floating_type (mode)
  538.      enum machine_mode mode;
  539. {
  540.   if (mode == SFmode)
  541.     return float_type_node;
  542.   if (mode == DFmode)
  543.     return double_type_node;
  544.   abort ();
  545. }
  546.  
  547. tree
  548. c_sizeof (type)
  549.      tree type;
  550. {
  551.   enum tree_code code = TREE_CODE (type);
  552.  
  553.   if (code == FUNCTION_TYPE)
  554.     {
  555.       if (pedantic)
  556.     warning ("sizeof applied to a function type");
  557.       return build_int (1);
  558.     }
  559.   if (code == VOID_TYPE)
  560.     {
  561.       if (pedantic)
  562.     warning ("sizeof applied to a void type");
  563.       return build_int (1);
  564.     }
  565.  
  566.   return size_in_bytes (type);
  567. }
  568.  
  569. tree
  570. c_sizeof_nowarn (type)
  571.      tree type;
  572. {
  573.   enum tree_code code = TREE_CODE (type);
  574.  
  575.   if (code == FUNCTION_TYPE
  576.       || code == VOID_TYPE)
  577.     return build_int (1);
  578.  
  579.   return size_in_bytes (type);
  580. }
  581.  
  582. /* Implement the __alignof keyword: Return the minimum required
  583.    alignment of TYPE, measured in bytes.  */
  584.  
  585. tree
  586. c_alignof (type)
  587.      tree type;
  588. {
  589.   enum tree_code code = TREE_CODE (type);
  590.  
  591.   if (pedantic)
  592.     warning ("ANSI C does not allow `__alignof'");
  593.  
  594.   if (code == FUNCTION_TYPE)
  595.     return build_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  596.  
  597.   if (code == VOID_TYPE)
  598.     return build_int (1);
  599.  
  600.   return build_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  601. }
  602.  
  603. /* Perform default promotions for C data used in expressions.
  604.    Arrays and functions are converted to pointers;
  605.    enumeral types or short or char, to int.
  606.    In addition, manifest constants symbols are replaced by their values.  */
  607.  
  608. tree
  609. default_conversion (exp)
  610.      tree exp;
  611. {
  612.   register tree dt = TREE_TYPE (exp);
  613.   register enum tree_code form = TREE_CODE (dt);
  614.  
  615.   if (TREE_CODE (exp) == CONST_DECL)
  616.     exp = DECL_INITIAL (exp);
  617.  
  618.   if (form == ENUMERAL_TYPE
  619.       || (form == INTEGER_TYPE
  620.       && (TYPE_PRECISION (dt)
  621.           < TYPE_PRECISION (integer_type_node))))
  622.     {
  623.       /* Traditionally, unsignedness is preserved in default promotions.  */
  624.       if (flag_traditional && TREE_UNSIGNED (dt))
  625.     return convert (unsigned_type_node, exp);
  626.       return convert (integer_type_node, exp);
  627.     }
  628.   if (flag_traditional && dt == float_type_node)
  629.     return convert (double_type_node, exp);
  630.   if (form == VOID_TYPE)
  631.     {
  632.       error ("void value not ignored as it ought to be");
  633.       return error_mark_node;
  634.     }
  635.   if (form == FUNCTION_TYPE)
  636.     {
  637.       return build_unary_op (ADDR_EXPR, exp, 0);
  638.     }
  639.   if (form == ARRAY_TYPE)
  640.     {
  641.       register tree adr;
  642.       if (TREE_CODE (exp) == INDIRECT_REF)
  643.     return convert (TYPE_POINTER_TO (TREE_TYPE (dt)),
  644.             TREE_OPERAND (exp, 0));
  645.  
  646.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  647.     {
  648.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  649.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  650.             TREE_OPERAND (exp, 0), op1);
  651.     }
  652.  
  653.       if (!lvalue_p (exp)
  654.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  655.     {
  656.       error ("invalid use of non-lvalue array");
  657.       return error_mark_node;
  658.     }
  659.  
  660. /* ??? This is not really quite correct
  661.    in that the type of the operand of ADDR_EXPR
  662.    is not the target type of the type of the ADDR_EXPR itself.
  663.    Question is, can this lossage be avoided?  */
  664.       adr = build (ADDR_EXPR, TYPE_POINTER_TO (TREE_TYPE (dt)), exp);
  665.       mark_addressable (exp);
  666.       TREE_LITERAL (adr) = staticp (exp);
  667.       TREE_VOLATILE (adr) = 0;   /* Default would be, same as EXP.  */
  668.       return adr;
  669.     }
  670.   return exp;
  671. }
  672.  
  673. /* Make an expression to refer to the COMPONENT field of
  674.    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
  675.  
  676. tree
  677. build_component_ref (datum, component)
  678.      tree datum, component;
  679. {
  680.   register tree basename = datum;
  681.   register tree basetype = TREE_TYPE (basename);
  682.   register enum tree_code form = TREE_CODE (basetype);
  683.   register tree field = NULL;
  684.   register tree ref;
  685.  
  686.   /* First, see if there is a field or component with name COMPONENT. */
  687.  
  688.   if (form == RECORD_TYPE || form == UNION_TYPE)
  689.     {
  690.       if (TYPE_SIZE (basetype) == 0)
  691.     {
  692.       incomplete_type_error (0, basetype);
  693.       return error_mark_node;
  694.     }
  695.  
  696.       /* Look up component name in the structure type definition.  */
  697.  
  698.       for (field = TYPE_FIELDS (basetype); field; field = TREE_CHAIN (field))
  699.     {
  700.       if (DECL_NAME (field) == component)
  701.         break;
  702.     }
  703.  
  704.       if (!field)
  705.     {
  706.       error (form == RECORD_TYPE
  707.          ? "structure has no member named `%s'"
  708.          : "union has no member named `%s'",
  709.          IDENTIFIER_POINTER (component));
  710.       return error_mark_node;
  711.     }
  712.  
  713.       ref = build (COMPONENT_REF, TREE_TYPE (field), basename, field);
  714.  
  715.       if (TREE_READONLY (basename) || TREE_READONLY (field))
  716.     TREE_READONLY (ref) = 1;
  717.       if (TREE_THIS_VOLATILE (basename) || TREE_VOLATILE (field))
  718.     TREE_THIS_VOLATILE (ref) = 1;
  719.  
  720.       return ref;
  721.     }
  722.   else if (form != ERROR_MARK)
  723.     error ("request for member `%s' in something not a structure or union",
  724.         IDENTIFIER_POINTER (component));
  725.  
  726.   return error_mark_node;
  727. }
  728.  
  729. /* Given an expression PTR for a pointer, return an expression
  730.    for the value pointed to.
  731.    ERRORSTRING is the name of the operator to appear in error messages.  */
  732.  
  733. tree
  734. build_indirect_ref (ptr, errorstring)
  735.      tree ptr;
  736.      char *errorstring;
  737. {
  738.   register tree pointer = default_conversion (ptr);
  739.   register tree dt = TREE_TYPE (pointer);
  740.  
  741.   if (TREE_CODE (dt) == POINTER_TYPE)
  742.     if (TREE_CODE (pointer) == ADDR_EXPR
  743.     && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  744.         == TREE_TYPE (dt)))
  745.       return TREE_OPERAND (pointer, 0);
  746.     else
  747.       {
  748.     tree t = TREE_TYPE (dt);
  749.     register tree ref = build (INDIRECT_REF,
  750.                    TYPE_MAIN_VARIANT (t), pointer);
  751.  
  752.     TREE_READONLY (ref) = TREE_READONLY (t);
  753.     TREE_VOLATILE (ref) = TREE_VOLATILE (t) || TREE_VOLATILE (pointer);
  754.     TREE_THIS_VOLATILE (ref) = TREE_VOLATILE (t);
  755.     return ref;
  756.       }
  757.   else if (TREE_CODE (pointer) != ERROR_MARK)
  758.     error ("invalid type argument of `%s'", errorstring);
  759.   return error_mark_node;
  760. }
  761.  
  762. /* This handles expressions of the form "a[i]", which denotes
  763.    an array reference.
  764.  
  765.    This is logically equivalent in C to *(a+i), but we may do it differently.
  766.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  767.    This avoids forcing the array out of registers, and can work on
  768.    arrays that are not lvalues (for example, members of structures returned
  769.    by functions).  */
  770.  
  771. tree
  772. build_array_ref (array, index)
  773.      tree array, index;
  774. {
  775.   if (index == 0)
  776.     {
  777.       error ("subscript missing in array reference");
  778.       return error_mark_node;
  779.     }
  780.  
  781.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  782.       && TREE_CODE (array) != INDIRECT_REF)
  783.     {
  784.       index = default_conversion (index);
  785.       if (index != error_mark_node
  786.       && TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
  787.     {
  788.       error ("array subscript is not an integer");
  789.       return error_mark_node;
  790.     }
  791.  
  792.       /* An array that is indexed by a non-constant
  793.      cannot be stored in a register; we must be able to do
  794.      address arithmetic on its address.
  795.      Likewise an array of elements of variable size.  */
  796.       if (TREE_CODE (index) != INTEGER_CST
  797.       || TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)
  798.     mark_addressable (array);
  799.  
  800.       if (pedantic && !lvalue_p (array))
  801.     warning ("ANSI C forbids subscripting non-lvalue array");
  802.  
  803.       return require_complete_type (build (ARRAY_REF,
  804.                        TREE_TYPE (TREE_TYPE (array)),
  805.                        array, index));
  806.     }
  807.  
  808.   {
  809.     tree ar = default_conversion (array);
  810.     tree ind = default_conversion (index);
  811.  
  812.     if ((TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE
  813.      && TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  814.     || (TREE_CODE (TREE_TYPE (ind)) == POINTER_TYPE
  815.         && TREE_CODE (TREE_TYPE (ar)) != INTEGER_TYPE))
  816.       {
  817.     error ("array subscript is not an integer");
  818.     return error_mark_node;
  819.       }
  820.  
  821.     return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind),
  822.                    "array indexing");
  823.   }
  824. }
  825.  
  826. /* Build a function call to function FUNCTION with parameters PARAMS.
  827.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  828.    TREE_VALUE of each node is a parameter-expression.
  829.    FUNCTION's data type may be a function type or a pointer-to-function.  */
  830.  
  831. tree
  832. build_function_call (function, params)
  833.      tree function, params;
  834. {
  835.   register tree fntype;
  836.   register tree value_type;
  837.   register tree coerced_params;
  838.   tree name = NULL_TREE;
  839.   tree actualparameterlist ();
  840.  
  841.   /* Convert anything with function type to a pointer-to-function.  */
  842.   if (TREE_CODE (function) == FUNCTION_DECL)
  843.     {
  844.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  845.      (because calling an inline function does not mean the function
  846.      needs to be separately compiled).  */
  847.       function = build (ADDR_EXPR, build_pointer_type (TREE_TYPE (function)),
  848.             function);
  849.     }
  850.   else
  851.     function = default_conversion (function);
  852.  
  853.   fntype = TREE_TYPE (function);
  854.  
  855.   if (TREE_CODE (fntype) == ERROR_MARK)
  856.     return error_mark_node;
  857.  
  858.   if (!(TREE_CODE (fntype) == POINTER_TYPE
  859.     && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
  860.     {
  861.       error ("called object is not a function");
  862.       return error_mark_node;
  863.     }
  864.  
  865.   /* fntype now gets the type of function pointed to.  */
  866.   fntype = TREE_TYPE (fntype);
  867.  
  868.   /* Convert the parameters to the types declared in the
  869.      function prototype, or apply default promotions.  */
  870.  
  871.   coerced_params = actualparameterlist (TYPE_ARG_TYPES (fntype), params, name);
  872.  
  873.   /* Recognize certain built-in functions so we can make tree-codes
  874.      other than CALL_EXPR.  We do this when it enables fold-const.c
  875.      to do something useful.  */
  876.  
  877.   if (TREE_CODE (function) == ADDR_EXPR
  878.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
  879.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  880.       {
  881.       case BUILT_IN_ABS:
  882.       case BUILT_IN_LABS:
  883.       case BUILT_IN_FABS:
  884.     if (coerced_params == 0)
  885.       return integer_zero_node;
  886.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  887.       }
  888.  
  889.   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
  890.   
  891.   {
  892.     register tree result = 
  893.       build (CALL_EXPR, value_type, function, coerced_params, NULL_TREE);
  894.  
  895.     TREE_VOLATILE (result) = 1;
  896.     if (value_type == void_type_node)
  897.       return result;
  898.     return require_complete_type (result);
  899.   }
  900. }
  901.  
  902. /* Convert the actual parameter expressions in the list VALUES
  903.    to the types in the list TYPELIST.
  904.    If parmdecls is exhausted, or when an element has NULL as its type,
  905.    perform the default conversions.
  906.  
  907.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  908.  
  909.    This is also where warnings about wrong number of args are generated.
  910.    
  911.    Return a list of expressions for the parameters as converted.
  912.  
  913.    Both VALUES and the returned value are chains of TREE_LIST nodes
  914.    with the elements of the list in the TREE_VALUE slots of those nodes.  */
  915.  
  916. tree
  917. actualparameterlist (typelist, values, name)
  918.      tree typelist, values, name;
  919. {
  920.   register tree typetail, valtail;
  921.   register tree result = NULL;
  922.  
  923.   for (valtail = values, typetail = typelist;
  924.        valtail;
  925.        valtail = TREE_CHAIN (valtail))
  926.     {
  927.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  928.       register tree val = TREE_VALUE (valtail);
  929.       register tree parm;
  930.  
  931.       if (type == void_type_node)
  932.     {
  933.       if (name)
  934.         error ("too many arguments to function `%s'",
  935.            IDENTIFIER_POINTER (name));
  936.       else
  937.         error ("too many arguments to function");
  938.       break;
  939.     }
  940.  
  941.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  942.       || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
  943.     val = default_conversion (val);
  944.  
  945.       val = require_complete_type (val);
  946.  
  947.       if (type != 0)
  948.     {
  949.       /* Formal parm type is specified by a function prototype.  */
  950.       tree parmval
  951.         = convert_for_assignment (type, val, "argument passing");
  952. #ifdef PROMOTE_PROTOTYPES
  953.       if (TREE_CODE (type) == INTEGER_TYPE
  954.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  955.         parmval = default_conversion (parmval);
  956. #endif
  957.       parm = build_tree_list (0, parmval);
  958.     }
  959.       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  960.                && (TYPE_PRECISION (TREE_TYPE (val))
  961.                < TYPE_PRECISION (double_type_node)))
  962.     /* Convert `float' to `double'.  */
  963.     parm = build_tree_list (NULL_TREE, convert (double_type_node, val));
  964.       else
  965.     /* Convert `short' and `char' to full-size `int'.  */
  966.     parm = build_tree_list (NULL_TREE, default_conversion (val));
  967.  
  968.       result = chainon (result, parm);
  969.       if (typetail)
  970.     typetail = TREE_CHAIN (typetail);
  971.     }
  972.  
  973.   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
  974.     {
  975.       if (name)
  976.     error ("too few arguments to function `%s'",
  977.            IDENTIFIER_POINTER (name));
  978.       else
  979.     error ("too few arguments to function");
  980.     }
  981.  
  982.   return result;
  983. }
  984.  
  985. /* Build a binary-operation expression, after performing default
  986.    conversions on the operands.  CODE is the kind of expression to build.  */
  987.  
  988. tree
  989. build_binary_op (code, arg1, arg2)
  990.      enum tree_code code;
  991.      tree arg1, arg2;
  992. {
  993.   return build_binary_op_nodefault (code, default_conversion (arg1),
  994.                     default_conversion (arg2));
  995. }
  996.  
  997. /* Build a binary-operation expression without default conversions.
  998.    CODE is the kind of expression to build.
  999.    This function differs from `build' in several ways:
  1000.    the data type of the result is computed and recorded in it,
  1001.    warnings are generated if arg data types are invalid,
  1002.    special handling for addition and subtraction of pointers is known,
  1003.    and some optimization is done (operations on narrow ints
  1004.    are done in the narrower type when that gives the same result).
  1005.    Constant folding is also done before the result is returned.
  1006.  
  1007.    Note that the operands will never have enumeral types
  1008.    because either they have just had the default conversions performed
  1009.    or they have both just been converted to some other type in which
  1010.    the arithmetic is to be done.  */
  1011.  
  1012. tree
  1013. build_binary_op_nodefault (code, op0, op1)
  1014.      enum tree_code code;
  1015.      tree op0, op1;
  1016. {
  1017.   tree dt0 = datatype (op0), dt1 = datatype (op1);
  1018.  
  1019.   /* The expression codes of the data types of the arguments tell us
  1020.      whether the arguments are integers, floating, pointers, etc.  */
  1021.   register enum tree_code code0 = TREE_CODE (dt0);
  1022.   register enum tree_code code1 = TREE_CODE (dt1);
  1023.  
  1024.   /* Expression code to give to the expression when it is built.
  1025.      Normally this is CODE, which is what the caller asked for,
  1026.      but in some special cases we change it.  */
  1027.   register enum tree_code resultcode = code;
  1028.  
  1029.   /* Data type in which the computation is to be performed.
  1030.      In the simplest cases this is the common type of the arguments.  */
  1031.   register tree result_type = NULL;
  1032.  
  1033.   /* Nonzero means operands have already been type-converted
  1034.      in whatever way is necessary.
  1035.      Zero means they need to be converted to RESULT_TYPE.  */
  1036.   int converted = 0;
  1037.  
  1038.   /* Nonzero means after finally constructing the expression
  1039.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  1040.   tree final_type = 0;
  1041.  
  1042.   /* Nonzero if this is an operation like MIN or MAX which can
  1043.      safely be computed in short if both args are promoted shorts.
  1044.      Also implies COMMON.
  1045.      -1 indicates a bitwise operation; this makes a difference
  1046.      in the exact conditions for when it is safe to do the operation
  1047.      in a narrower mode.  */
  1048.   int shorten = 0;
  1049.  
  1050.   /* Nonzero if this is a comparison operation;
  1051.      if both args are promoted shorts, compare the original shorts.
  1052.      Also implies COMMON.  */
  1053.   int short_compare = 0;
  1054.  
  1055.   /* Nonzero if this is a right-shift operation, which can be computed on the
  1056.      original short and then promoted if the operand is a promoted short.  */
  1057.   int short_shift = 0;
  1058.  
  1059.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  1060.   int common = 0;
  1061.  
  1062.   /* If an error was already reported for one of the arguments,
  1063.      avoid reporting another error.  */
  1064.  
  1065.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  1066.     return error_mark_node;
  1067.  
  1068.   switch (code)
  1069.     {
  1070.     case PLUS_EXPR:
  1071.       /* Handle the pointer + int case.  */
  1072.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1073.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  1074.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  1075.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  1076.       else
  1077.     common = 1;
  1078.       break;
  1079.  
  1080.     case MINUS_EXPR:
  1081.       /* Subtraction of two similar pointers.
  1082.      We must subtract them as integers, then divide by object size.  */
  1083.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  1084.       && comp_target_types (dt0, dt1))
  1085.     return pointer_diff (op0, op1);
  1086.       /* Handle pointer minus int.  Just like pointer plus int.  */
  1087.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1088.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  1089.       else
  1090.     common = 1;
  1091.       break;
  1092.  
  1093.     case MULT_EXPR:
  1094.       common = 1;
  1095.       break;
  1096.  
  1097.     case TRUNC_DIV_EXPR:
  1098.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1099.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1100.     {
  1101.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  1102.         resultcode = RDIV_EXPR;
  1103.       else
  1104.         shorten = 1;
  1105.       common = 1;
  1106.     }
  1107.       break;
  1108.  
  1109.     case BIT_AND_EXPR:
  1110.     case BIT_ANDTC_EXPR:
  1111.     case BIT_IOR_EXPR:
  1112.     case BIT_XOR_EXPR:
  1113.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1114.     shorten = -1;
  1115.       /* If one operand is a constant, and the other is a short type
  1116.      that has been converted to an int,
  1117.      really do the work in the short type and then convert the
  1118.      result to int.  If we are lucky, the constant will be 0 or 1
  1119.      in the short type, making the entire operation go away.  */
  1120.       if (TREE_CODE (op0) == INTEGER_CST
  1121.       && TREE_CODE (op1) == NOP_EXPR
  1122.       && TYPE_PRECISION (dt1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  1123.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  1124.     {
  1125.       final_type = result_type;
  1126.       op1 = TREE_OPERAND (op1, 0);
  1127.       result_type = TREE_TYPE (op1);
  1128.     }
  1129.       if (TREE_CODE (op1) == INTEGER_CST
  1130.       && TREE_CODE (op0) == NOP_EXPR
  1131.       && TYPE_PRECISION (dt0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  1132.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  1133.     {
  1134.       final_type = result_type;
  1135.       op0 = TREE_OPERAND (op0, 0);
  1136.       result_type = TREE_TYPE (op0);
  1137.     }
  1138.       break;
  1139.  
  1140.     case TRUNC_MOD_EXPR:
  1141.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1142.     shorten = 1;
  1143.       break;
  1144.  
  1145.     case TRUTH_ANDIF_EXPR:
  1146.     case TRUTH_ORIF_EXPR:
  1147.     case TRUTH_AND_EXPR:
  1148.     case TRUTH_OR_EXPR:
  1149.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE || code0 == REAL_TYPE)
  1150.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE || code1 == REAL_TYPE))
  1151.     {
  1152.       /* Result of these operations is always an int,
  1153.          but that does not mean the operands should be
  1154.          converted to ints!  */
  1155.       result_type = integer_type_node;
  1156.       converted = 1;
  1157.     }
  1158.       break;
  1159.  
  1160.       /* Shift operations: result has same type as first operand.
  1161.      Also set SHORT_SHIFT if shifting rightward.  */
  1162.  
  1163.     case RSHIFT_EXPR:
  1164.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1165.     {
  1166.       result_type = dt0;
  1167.       if (TREE_CODE (op1) == INTEGER_CST
  1168.           && TREE_INT_CST_LOW (op1) > 0)
  1169.         short_shift = 1;
  1170.     }
  1171.       break;
  1172.  
  1173.     case LSHIFT_EXPR:
  1174.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1175.     {
  1176.       result_type = dt0;
  1177.       if (TREE_CODE (op1) == INTEGER_CST
  1178.           && TREE_INT_CST_LOW (op1) < 0)
  1179.         short_shift = 1;
  1180.     }
  1181.       break;
  1182.  
  1183.     case RROTATE_EXPR:
  1184.     case LROTATE_EXPR:
  1185.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1186.     result_type = dt0;
  1187.       break;
  1188.  
  1189.     case EQ_EXPR:
  1190.     case NE_EXPR:
  1191.       /* Result of comparison is always int,
  1192.      but don't convert the args to int!  */
  1193.       result_type = integer_type_node;
  1194.       converted = 1;
  1195.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1196.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1197.     short_compare = 1;
  1198.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1199.     {
  1200.       register tree tt0 = TREE_TYPE (dt0);
  1201.       register tree tt1 = TREE_TYPE (dt1);
  1202.       /* Anything compares with void *.  void * compares with anything.
  1203.          Otherwise, the targets must be the same.  */
  1204.       if (comp_target_types (dt0, dt1))
  1205.         ;
  1206.       else if (tt0 == void_type_node)
  1207.         {
  1208.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
  1209.         warning ("ANSI C forbids comparison of `void *' with function pointer");
  1210.         }
  1211.       else if (tt1 == void_type_node)
  1212.         {
  1213.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
  1214.         warning ("ANSI C forbids comparison of `void *' with function pointer");
  1215.         }
  1216.       else
  1217.         warning ("comparison of distinct pointer types lacks a cast");
  1218.     }
  1219.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  1220.         && integer_zerop (op1))
  1221.     op1 = null_pointer_node;
  1222.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  1223.         && integer_zerop (op0))
  1224.     op0 = null_pointer_node;
  1225.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1226.     {
  1227.       if (! flag_traditional)
  1228.         warning ("comparison between pointer and integer");
  1229.       op1 = convert (TREE_TYPE (op0), op1);
  1230.     }
  1231.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  1232.     {
  1233.       if (! flag_traditional)
  1234.         warning ("comparison between pointer and integer");
  1235.       op0 = convert (TREE_TYPE (op1), op0);
  1236.     }
  1237.       else
  1238.     /* If args are not valid, clear out RESULT_TYPE
  1239.        to cause an error message later.  */
  1240.     result_type = 0;
  1241.       break;
  1242.  
  1243.     case MAX_EXPR:
  1244.     case MIN_EXPR:
  1245.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1246.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1247.     shorten = 1;
  1248.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1249.     {
  1250.       if (! comp_target_types (dt0, dt1))
  1251.         warning ("comparison of distinct pointer types lacks a cast");
  1252.       else if (pedantic 
  1253.            && TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1254.         warning ("ANSI C forbids ordered comparisons of pointers to functions");
  1255.       result_type = commontype (dt0, dt1);
  1256.     }
  1257.       break;
  1258.  
  1259.     case LE_EXPR:
  1260.     case GE_EXPR:
  1261.     case LT_EXPR:
  1262.     case GT_EXPR:
  1263.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1264.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1265.     short_compare = 1;
  1266.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  1267.     {
  1268.       if (! comp_target_types (dt0, dt1))
  1269.         warning ("comparison of distinct pointer types lacks a cast");
  1270.       else if (pedantic 
  1271.            && TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1272.         warning ("ANSI C forbids ordered comparisons of pointers to functions");
  1273.       result_type = integer_type_node;
  1274.     }
  1275.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  1276.         && integer_zerop (op1))
  1277.     {
  1278.       result_type = integer_type_node;
  1279.       op1 = null_pointer_node;
  1280.       if (! flag_traditional)
  1281.         warning ("ordered comparison of pointer with integer zero");
  1282.     }
  1283.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  1284.         && integer_zerop (op0))
  1285.     {
  1286.       result_type = integer_type_node;
  1287.       op0 = null_pointer_node;
  1288.       if (pedantic)
  1289.         warning ("ordered comparison of pointer with integer zero");
  1290.     }
  1291.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1292.     {
  1293.       if (! flag_traditional)
  1294.         warning ("comparison between pointer and integer");
  1295.       op1 = convert (TREE_TYPE (op0), op1);
  1296.     }
  1297.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  1298.     {
  1299.       if (! flag_traditional)
  1300.         warning ("comparison between pointer and integer");
  1301.       op0 = convert (TREE_TYPE (op1), op0);
  1302.     }
  1303.       converted = 1;
  1304.       break;
  1305.     }
  1306.  
  1307.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  1308.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  1309.     {
  1310.       if (shorten || common || short_compare)
  1311.     result_type = commontype (dt0, dt1);
  1312.  
  1313.       /* For certain operations (which identify themselves by shorten != 0)
  1314.      if both args were extended from the same smaller type,
  1315.      do the arithmetic in that type and then extend.
  1316.  
  1317.      shorten !=0 and !=1 indicates a bitwise operation.
  1318.      For them, this optimization is safe only if
  1319.      both args are zero-extended or both are sign-extended.
  1320.      Otherwise, we might change the result.
  1321.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  1322.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  1323.  
  1324.       if (shorten)
  1325.     {
  1326.       int unsigned0, unsigned1;
  1327.       tree arg0 = get_narrower (op0, &unsigned0);
  1328.       tree arg1 = get_narrower (op1, &unsigned1);
  1329.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  1330.       int uns = TREE_UNSIGNED (result_type);
  1331.       tree type;
  1332.  
  1333.       final_type = result_type;
  1334.  
  1335.       /* Handle the case that OP0 does not *contain* a conversion
  1336.          but it *requires* conversion to FINAL_TYPE.  */
  1337.  
  1338.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  1339.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  1340.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  1341.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  1342.  
  1343.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  1344.  
  1345.       /* For bitwise operations, signedness of nominal type
  1346.          does not matter.  Consider only how operands were extended.  */
  1347.       if (shorten == -1)
  1348.         uns = unsigned0;
  1349.  
  1350.       /* Note that in all three cases below we refrain from optimizing
  1351.          an unsigned operation on sign-extended args.
  1352.          That would not be valid.  */
  1353.  
  1354.       /* Both args variable: if both extended in same way
  1355.          from same width, do it in that width.
  1356.          Do it unsigned if args were zero-extended.  */
  1357.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  1358.            < TYPE_PRECISION (result_type))
  1359.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  1360.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  1361.           && unsigned0 == unsigned1
  1362.           && (unsigned0 || !uns))
  1363.         result_type
  1364.           = signed_or_unsigned_type (unsigned0,
  1365.                      commontype (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  1366.       else if (TREE_CODE (arg0) == INTEGER_CST
  1367.            && (unsigned1 || !uns)
  1368.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  1369.                < TYPE_PRECISION (result_type))
  1370.            && (type = signed_or_unsigned_type (unsigned1,
  1371.                                TREE_TYPE (arg1)),
  1372.                int_fits_type_p (arg0, type)))
  1373.         result_type = type;
  1374.       else if (TREE_CODE (arg1) == INTEGER_CST
  1375.            && (unsigned0 || !uns)
  1376.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  1377.                < TYPE_PRECISION (result_type))
  1378.            && (type = signed_or_unsigned_type (unsigned0,
  1379.                                TREE_TYPE (arg0)),
  1380.                int_fits_type_p (arg1, type)))
  1381.         result_type = type;
  1382.     }
  1383.  
  1384.       /* Shifts can be shortened if shifting right.  */
  1385.  
  1386.       if (short_shift)
  1387.     {
  1388.       int unsigned_arg;
  1389.       tree arg0 = get_narrower (op0, &unsigned_arg);
  1390.  
  1391.       final_type = result_type;
  1392.  
  1393.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  1394.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  1395.  
  1396.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  1397.           /* If arg is sign-extended and then unsigned-shifted,
  1398.          we can simulate this with a signed shift in arg's type
  1399.          only if the extended result is at least twice as wide
  1400.          as the arg.  Otherwise, the shift could use up all the
  1401.          ones made by sign-extension and bring in zeros.
  1402.          We can't optimize that case at all, but in most machines
  1403.          it never happens because available widths are 2**N.  */
  1404.           && (!TREE_UNSIGNED (final_type)
  1405.           || unsigned_arg
  1406.           || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
  1407.         {
  1408.           /* Convert the shift-count to its nominal type.  */
  1409.           if (TREE_TYPE (op1) != result_type)
  1410.         op1 = convert (result_type, op1);
  1411.           /* Do an unsigned shift if the operand was zero-extended.  */
  1412.           result_type
  1413.         = signed_or_unsigned_type (unsigned_arg,
  1414.                        TREE_TYPE (arg0));
  1415.           /* Convert value-to-be-shifted to that type.  */
  1416.           if (TREE_TYPE (op0) != result_type)
  1417.         op0 = convert (result_type, op0);
  1418.           converted = 1;
  1419.         }
  1420.     }
  1421.  
  1422.       /* Comparison operations are shortened too but differently.
  1423.      They identify themselves by setting short_compare = 1.  */
  1424.  
  1425.       if (short_compare)
  1426.     {
  1427.       /* Don't write &op0, etc., because that would prevent op0
  1428.          from being kept in a register.
  1429.          Instead, make copies of the our local variables and
  1430.          pass the copies by reference, then copy them back afterward.  */
  1431.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  1432.       enum tree_code xresultcode = resultcode;
  1433.       tree val 
  1434.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  1435.       if (val != 0)
  1436.         return val;
  1437.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  1438.       resultcode = xresultcode;
  1439.     }
  1440.     }
  1441.  
  1442.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  1443.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  1444.      Then the expression will be built.
  1445.      It will be given type FINAL_TYPE if that is nonzero;
  1446.      otherwise, it will be given type RESULT_TYPE.  */
  1447.  
  1448.   if (!result_type)
  1449.     {
  1450.       binary_op_error (code);
  1451.       return error_mark_node;
  1452.     }
  1453.  
  1454.   if (! converted)
  1455.     {
  1456.       if (TREE_TYPE (op0) != result_type)
  1457.     op0 = convert (result_type, op0); 
  1458.       if (TREE_TYPE (op1) != result_type)
  1459.     op1 = convert (result_type, op1); 
  1460.     }
  1461.  
  1462.   {
  1463.     register tree result = build (resultcode, result_type, op0, op1);
  1464.     register tree folded;
  1465.  
  1466.     folded = fold (result);
  1467.     if (folded == result)
  1468.       TREE_LITERAL (folded) = TREE_LITERAL (op0) & TREE_LITERAL (op1);
  1469.     if (final_type != 0)
  1470.       return convert (final_type, folded);
  1471.     return folded;
  1472.   }
  1473. }
  1474.  
  1475. /* Return a tree for the sum or difference (RESULTCODE says which)
  1476.    of pointer PTROP and integer INTOP.  */
  1477.  
  1478. static tree
  1479. pointer_int_sum (resultcode, ptrop, intop)
  1480.      enum tree_code resultcode;
  1481.      register tree ptrop, intop;
  1482. {
  1483.   tree size_exp;
  1484.  
  1485.   register tree result;
  1486.   register tree folded;
  1487.  
  1488.   /* The result is a pointer of the same type that is being added.  */
  1489.  
  1490.   register tree result_type = datatype (ptrop);
  1491.  
  1492.   if (TREE_TYPE (result_type) == void_type_node)
  1493.     {
  1494.       if (pedantic)
  1495.     warning ("pointer of type `void *' used in arithmetic");
  1496.       size_exp = integer_one_node;
  1497.     }
  1498.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  1499.     {
  1500.       if (pedantic)
  1501.     warning ("pointer to a function used in arithmetic");
  1502.       size_exp = integer_one_node;
  1503.     }
  1504.   else
  1505.     size_exp = size_in_bytes (TREE_TYPE (result_type));
  1506.  
  1507.   /* If what we are about to multiply by the size of the elements
  1508.      contains a constant term, apply distributive law
  1509.      and multiply that constant term separately.
  1510.      This helps produce common subexpressions.  */
  1511.  
  1512.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  1513.       && ! TREE_LITERAL (intop)
  1514.       && TREE_LITERAL (TREE_OPERAND (intop, 1))
  1515.       && TREE_LITERAL (size_exp))
  1516.     {
  1517.       enum tree_code subcode = resultcode;
  1518.       if (TREE_CODE (intop) == MINUS_EXPR)
  1519.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  1520.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1));
  1521.       intop = TREE_OPERAND (intop, 0);
  1522.     }
  1523.  
  1524.   /* Convert the integer argument to a type the same size as a pointer
  1525.      so the multiply won't overflow spuriously.  */
  1526.  
  1527.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  1528.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  1529.  
  1530.   /* Replace the integer argument
  1531.      with a suitable product by the object size.  */
  1532.  
  1533.   intop = build_binary_op (MULT_EXPR, intop, size_exp);
  1534.  
  1535.   /* Create the sum or difference.  */
  1536.  
  1537.   result = build (resultcode, result_type, ptrop, intop);
  1538.  
  1539.   folded = fold (result);
  1540.   if (folded == result)
  1541.     TREE_LITERAL (folded) = TREE_LITERAL (ptrop) & TREE_LITERAL (intop);
  1542.   return folded;
  1543. }
  1544.  
  1545. /* Return a tree for the difference of pointers OP0 and OP1.
  1546.    The resulting tree has type int.  */
  1547.  
  1548. static tree
  1549. pointer_diff (op0, op1)
  1550.      register tree op0, op1;
  1551. {
  1552.   tree dt0 = datatype (op0);
  1553.   enum tree_code resultcode;
  1554.   register tree result, folded;
  1555.   tree restype = type_for_size (POINTER_SIZE, 0);
  1556.  
  1557.   if (pedantic)
  1558.     {
  1559.       if (TREE_CODE (TREE_TYPE (dt0)) == VOID_TYPE)
  1560.     warning ("pointer of type `void *' used in subtraction");
  1561.       if (TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1562.     warning ("pointer to a function used in subtraction");
  1563.     }
  1564.  
  1565.   /* First do the subtraction as integers;
  1566.      then drop through to build the divide operator.  */
  1567.  
  1568.   op0 = build_binary_op (MINUS_EXPR,
  1569.              convert (restype, op0), convert (restype, op1));
  1570.   op1 = ((TREE_TYPE (dt0) == void_type_node
  1571.       || TREE_CODE (TREE_TYPE (dt0)) == FUNCTION_TYPE)
  1572.      ? integer_one_node
  1573.      : size_in_bytes (TREE_TYPE (dt0)));
  1574.  
  1575.   /* By altering RESULTCODE, we direct this function to build
  1576.      the division operation.  If dividing by a power of 2,
  1577.      use floor-division (rounding down) since that is what
  1578.      a shift insn does.  Otherwise, since we can't use a shift anyway,
  1579.      use whichever kind of rounding this machine does most easily.  */
  1580.  
  1581.   if (TREE_CODE (op1) == INTEGER_CST
  1582.       && -1 == exact_log2 (TREE_INT_CST_LOW (op1)))
  1583.     resultcode = FLOOR_DIV_EXPR;
  1584.   else
  1585.     resultcode = EASY_DIV_EXPR;
  1586.  
  1587.   /* Create the sum or difference.  */
  1588.  
  1589.   result = build (resultcode, restype, op0, op1);
  1590.  
  1591.   folded = fold (result);
  1592.   if (folded == result)
  1593.     TREE_LITERAL (folded) = TREE_LITERAL (op0) & TREE_LITERAL (op1);
  1594.   return folded;
  1595. }
  1596.  
  1597. /* Print an error message for invalid operands to arith operation CODE.  */
  1598.  
  1599. static void
  1600. binary_op_error (code)
  1601.      enum tree_code code;
  1602. {
  1603.   register char *opname;
  1604.   switch (code)
  1605.     {
  1606.     case PLUS_EXPR:
  1607.       opname = "+"; break;
  1608.     case MINUS_EXPR:
  1609.       opname = "-"; break;
  1610.     case MULT_EXPR:
  1611.       opname = "*"; break;
  1612.     case MAX_EXPR:
  1613.       opname = "max"; break;
  1614.     case MIN_EXPR:
  1615.       opname = "min"; break;
  1616.     case EQ_EXPR:
  1617.       opname = "=="; break;
  1618.     case NE_EXPR:
  1619.       opname = "!="; break;
  1620.     case LE_EXPR:
  1621.       opname = "<="; break;
  1622.     case GE_EXPR:
  1623.       opname = ">="; break;
  1624.     case LT_EXPR:
  1625.       opname = "<"; break;
  1626.     case GT_EXPR:
  1627.       opname = ">"; break;
  1628.     case LSHIFT_EXPR:
  1629.       opname = "<<"; break;
  1630.     case RSHIFT_EXPR:
  1631.       opname = ">>"; break;
  1632.     case TRUNC_MOD_EXPR:
  1633.       opname = "%"; break;
  1634.     case TRUNC_DIV_EXPR:
  1635.       opname = "/"; break;
  1636.     case BIT_AND_EXPR:
  1637.       opname = "&"; break;
  1638.     case BIT_IOR_EXPR:
  1639.       opname = "|"; break;
  1640.     case TRUTH_ANDIF_EXPR:
  1641.       opname = "&&"; break;
  1642.     case TRUTH_ORIF_EXPR:
  1643.       opname = "||"; break;
  1644.     case BIT_XOR_EXPR:
  1645.       opname = "^"; break;
  1646.     }
  1647.   error ("invalid operands to binary %s", opname);
  1648. }
  1649.  
  1650. /* Subroutine of build_binary_op_nodefault, used for comparison operations.
  1651.    See if the operands have both been converted from subword integer types
  1652.    and, if so, perhaps change them both back to their original type.
  1653.  
  1654.    The arguments of this function are all pointers to local variables
  1655.    of build_binary_op_nodefault: OP0_PTR is &OP0, OP1_PTR is &OP1,
  1656.    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
  1657.  
  1658.    If this function returns nonzero, it means that the comparison has
  1659.    a constant value.  What this function returns is an expression for
  1660.    that value.  */
  1661.  
  1662. static tree
  1663. shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
  1664.      tree *op0_ptr, *op1_ptr;
  1665.      tree *restype_ptr;
  1666.      enum tree_code *rescode_ptr;
  1667. {
  1668.   register tree type;
  1669.   tree op0 = *op0_ptr;
  1670.   tree op1 = *op1_ptr;
  1671.   int unsignedp0, unsignedp1;
  1672.   int real1, real2;
  1673.   tree primop0, primop1;
  1674.   enum tree_code code = *rescode_ptr;
  1675.  
  1676.   /* Throw away any conversions to wider types
  1677.      already present in the operands.  */
  1678.  
  1679.   primop0 = get_narrower (op0, &unsignedp0);
  1680.   primop1 = get_narrower (op1, &unsignedp1);
  1681.  
  1682.   /* Handle the case that OP0 does not *contain* a conversion
  1683.      but it *requires* conversion to FINAL_TYPE.  */
  1684.  
  1685.   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
  1686.     unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
  1687.   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
  1688.     unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
  1689.  
  1690.   /* If one of the operands must be floated, we cannot optimize.  */
  1691.   real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
  1692.   real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
  1693.  
  1694.   /* If first arg is constant, swap the args (changing operation
  1695.      so value is preserved), for canonicalization.  */
  1696.  
  1697.   if (TREE_LITERAL (primop0))
  1698.     {
  1699.       register tree tem = primop0;
  1700.       register int temi = unsignedp0;
  1701.       primop0 = primop1;
  1702.       primop1 = tem;
  1703.       tem = op0;
  1704.       op0 = op1;
  1705.       op1 = tem;
  1706.       *op0_ptr = op0;
  1707.       *op1_ptr = op1;
  1708.       unsignedp0 = unsignedp1;
  1709.       unsignedp1 = temi;
  1710.       temi = real1;
  1711.       real1 = real2;
  1712.       real2 = temi;
  1713.  
  1714.       switch (code)
  1715.     {
  1716.     case LT_EXPR:
  1717.       code = GT_EXPR;
  1718.       break;
  1719.     case GT_EXPR:
  1720.       code = LT_EXPR;
  1721.       break;
  1722.     case LE_EXPR:
  1723.       code = GE_EXPR;
  1724.       break;
  1725.     case GE_EXPR:
  1726.       code = LE_EXPR;
  1727.       break;
  1728.     }
  1729.       *rescode_ptr = code;
  1730.     }
  1731.  
  1732.   /* If comparing an integer against a constant more bits wide,
  1733.      maybe we can deduce a value of 1 or 0 independent of the data.
  1734.      Or else truncate the constant now
  1735.      rather than extend the variable at run time.
  1736.  
  1737.      This is only interesting if the constant is the wider arg.
  1738.      Also, it is not safe if the constant is unsigned and the
  1739.      variable arg is signed, since in this case the variable
  1740.      would be sign-extended and then regarded as unsigned.
  1741.      Our technique fails in this case because the lowest/highest
  1742.      possible unsigned results don't follow naturally from the
  1743.      lowest/highest possible values of the variable operand.
  1744.      For just EQ_EXPR and NE_EXPR there is another technique that
  1745.      could be used: see if the constant can be faithfully represented
  1746.      in the other operand's type, by truncating it and reextending it
  1747.      and see if that preserves the constant's value.  */
  1748.  
  1749.   if (!real1 && !real2
  1750.       && TREE_CODE (primop1) == INTEGER_CST
  1751.       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
  1752.     {
  1753.       int min_gt, max_gt, min_lt, max_lt;
  1754.       tree maxval, minval;
  1755.       /* 1 if comparison is nominally unsigned.  */
  1756.       int unsignedp = TREE_UNSIGNED (*restype_ptr);
  1757.       tree val;
  1758.  
  1759.       type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
  1760.  
  1761.       maxval = TYPE_MAX_VALUE (type);
  1762.       minval = TYPE_MIN_VALUE (type);
  1763.  
  1764.       if (unsignedp && !unsignedp0)
  1765.     *restype_ptr = signed_type (*restype_ptr);
  1766.  
  1767.       if (TREE_TYPE (primop1) != *restype_ptr)
  1768.     primop1 = convert (*restype_ptr, primop1);
  1769.       if (type != *restype_ptr)
  1770.     {
  1771.       minval = convert (*restype_ptr, minval);
  1772.       maxval = convert (*restype_ptr, maxval);
  1773.     }
  1774.  
  1775.       if (unsignedp && unsignedp0)
  1776.     {
  1777.       min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
  1778.       max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
  1779.       min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
  1780.       max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
  1781.     }
  1782.       else
  1783.     {
  1784.       min_gt = INT_CST_LT (primop1, minval);
  1785.       max_gt = INT_CST_LT (primop1, maxval);
  1786.       min_lt = INT_CST_LT (minval, primop1);
  1787.       max_lt = INT_CST_LT (maxval, primop1);
  1788.     }
  1789.  
  1790.       val = 0;
  1791.       switch (code)
  1792.     {
  1793.     case NE_EXPR:
  1794.       if (max_lt || min_gt)
  1795.         val = integer_one_node;
  1796.       break;
  1797.  
  1798.     case EQ_EXPR:
  1799.       if (max_lt || min_gt)
  1800.         val = integer_zero_node;
  1801.       break;
  1802.  
  1803.     case LT_EXPR:
  1804.       if (max_lt)
  1805.         val = integer_one_node;
  1806.       if (!min_lt)
  1807.         val = integer_zero_node;
  1808.       break;
  1809.  
  1810.     case GT_EXPR:
  1811.       if (min_gt)
  1812.         val = integer_one_node;
  1813.       if (!max_gt)
  1814.         val = integer_zero_node;
  1815.       break;
  1816.  
  1817.     case LE_EXPR:
  1818.       if (!max_gt)
  1819.         val = integer_one_node;
  1820.       if (min_gt)
  1821.         val = integer_zero_node;
  1822.       break;
  1823.  
  1824.     case GE_EXPR:
  1825.       if (!min_lt)
  1826.         val = integer_one_node;
  1827.       if (max_lt)
  1828.         val = integer_zero_node;
  1829.       break;
  1830.     }
  1831.  
  1832.       /* If primop0 was sign-extended and unsigned comparison specd,
  1833.      we did a signed comparison above using the signed type bounds.
  1834.      But the comparison we output must be unsigned.
  1835.  
  1836.      Also, for inequalities, VAL is no good; but if the signed
  1837.      comparison had *any* fixed result, it follows that the
  1838.      unsigned comparison just tests the sign in reverse
  1839.      (positive values are LE, negative ones GE).
  1840.      So we can generate an unsigned comparison
  1841.      against an extreme value of the signed type.  */
  1842.  
  1843.       if (unsignedp && !unsignedp0)
  1844.     {
  1845.       if (val != 0)
  1846.         switch (code)
  1847.           {
  1848.           case LT_EXPR:
  1849.           case GE_EXPR:
  1850.         primop1 = TYPE_MIN_VALUE (type);
  1851.         val = 0;
  1852.         break;
  1853.  
  1854.           case LE_EXPR:
  1855.           case GT_EXPR:
  1856.         primop1 = TYPE_MAX_VALUE (type);
  1857.         val = 0;
  1858.         break;
  1859.           }
  1860.       type = unsigned_type (type);
  1861.     }
  1862.  
  1863.       if (max_lt && !unsignedp0)
  1864.     {
  1865.       /* This is the case of (char)x >?< 0x80, which people used to use
  1866.          expecting old C compilers to change the 0x80 into -0x80.  */
  1867.       if (val == integer_zero_node)
  1868.         warning ("comparison is always 0 due to limited range of data type");
  1869.       if (val == integer_one_node)
  1870.         warning ("comparison is always 1 due to limited range of data type");
  1871.     }
  1872.  
  1873.       if (val != 0)
  1874.     {
  1875.       /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
  1876.       if (TREE_VOLATILE (primop0))
  1877.         return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
  1878.       return val;
  1879.     }
  1880.  
  1881.       /* Value is not predetermined, but do the comparison
  1882.      in the type of the operand that is not constant.
  1883.      TYPE is already properly set.  */
  1884.     }
  1885.   else if (real1 && real2
  1886.        && TYPE_PRECISION (TREE_TYPE (primop0)) == TYPE_PRECISION (TREE_TYPE (primop1)))
  1887.     type = TREE_TYPE (primop0);
  1888.  
  1889.   /* If args' natural types are both narrower than nominal type
  1890.      and both extend in the same manner, compare them
  1891.      in the type of the wider arg.
  1892.      Otherwise must actually extend both to the nominal
  1893.      common type lest different ways of extending
  1894.      alter the result.
  1895.      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
  1896.  
  1897.   else if (unsignedp0 == unsignedp1 && real1 == real2
  1898.        && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
  1899.        && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
  1900.     {
  1901.       type = commontype (TREE_TYPE (primop0), TREE_TYPE (primop1));
  1902.       type = signed_or_unsigned_type (unsignedp0
  1903.                       || TREE_UNSIGNED (*restype_ptr),
  1904.                       type);
  1905.       /* Make sure shorter operand is extended the right way
  1906.      to match the longer operand.  */
  1907.       primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
  1908.              primop0);
  1909.       primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
  1910.              primop1);
  1911.     }
  1912.   else
  1913.     {
  1914.       /* Here we must do the comparison on the nominal type
  1915.      using the args exactly as we received them.  */
  1916.       type = *restype_ptr;
  1917.       primop0 = op0;
  1918.       primop1 = op1;
  1919.     }
  1920.  
  1921.   *op0_ptr = convert (type, primop0);
  1922.   *op1_ptr = convert (type, primop1);
  1923.  
  1924.   *restype_ptr = integer_type_node;
  1925.  
  1926.   return 0;
  1927. }
  1928.  
  1929. /* Construct and perhaps optimize a tree representation
  1930.    for a unary operation.  CODE, a tree_code, specifies the operation
  1931.    and XARG is the operand.  NOCONVERT nonzero suppresses
  1932.    the default promotions (such as from short to int).  */
  1933.  
  1934. tree
  1935. build_unary_op (code, xarg, noconvert)
  1936.      enum tree_code code;
  1937.      tree xarg;
  1938.      int noconvert;
  1939. {
  1940.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  1941.   register tree arg = xarg;
  1942.   register tree argtype = 0;
  1943.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  1944.   char *errstring = NULL;
  1945.   tree val;
  1946.  
  1947.   if (typecode == ERROR_MARK)
  1948.     return error_mark_node;
  1949.   if (typecode == ENUMERAL_TYPE)
  1950.     typecode = INTEGER_TYPE;
  1951.  
  1952.   switch (code)
  1953.     {
  1954.     case CONVERT_EXPR:
  1955.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  1956.         errstring = "wrong type argument to unary plus";
  1957.       /* This is used for unary plus, because a CONVERT_EXPR
  1958.      is enough to prevent anybody from looking inside for
  1959.      associativity, but won't generate any code.
  1960.      Any argument is ok.  */
  1961.       break;
  1962.  
  1963.     case NEGATE_EXPR:
  1964.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  1965.         errstring = "wrong type argument to unary minus";
  1966.       else if (!noconvert)
  1967.     arg = default_conversion (arg);
  1968.       break;
  1969.  
  1970.     case BIT_NOT_EXPR:
  1971.       if (typecode != INTEGER_TYPE)
  1972.         errstring = "wrong type argument to bit-complement";
  1973.       else if (!noconvert)
  1974.     arg = default_conversion (arg);
  1975.       break;
  1976.  
  1977.     case ABS_EXPR:
  1978.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
  1979.         errstring = "wrong type argument to abs";
  1980.       else if (!noconvert)
  1981.     arg = default_conversion (arg);
  1982.       break;
  1983.  
  1984.     case TRUTH_NOT_EXPR:
  1985.       if (typecode != INTEGER_TYPE
  1986.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  1987.       /* This will convert to a pointer.  */
  1988.       && typecode != ARRAY_TYPE)
  1989.     {
  1990.       errstring = "wrong type argument to unary exclamation mark";
  1991.       break;
  1992.     }
  1993.       arg = truthvalue_conversion (arg);
  1994.       if (TREE_CODE (arg) == NE_EXPR)
  1995.     {
  1996.       TREE_SET_CODE (arg, EQ_EXPR);
  1997.       return arg;
  1998.     }
  1999.       if (TREE_CODE (arg) == EQ_EXPR)
  2000.     {
  2001.       TREE_SET_CODE (arg, NE_EXPR);
  2002.       return arg;
  2003.     }
  2004.       if (TREE_CODE (arg) == TRUTH_NOT_EXPR)
  2005.     {
  2006.       return TREE_OPERAND (arg, 0);
  2007.     }
  2008.       break;
  2009.  
  2010.     case NOP_EXPR:
  2011.       break;
  2012.       
  2013.     case PREINCREMENT_EXPR:
  2014.     case POSTINCREMENT_EXPR:
  2015.     case PREDECREMENT_EXPR:
  2016.     case POSTDECREMENT_EXPR:
  2017.       /* Handle complex lvalues (when permitted)
  2018.      by reduction to simpler cases.  */
  2019.  
  2020.       val = unary_complex_lvalue (code, arg);
  2021.       if (val != 0)
  2022.     return val;
  2023.  
  2024.       /* Report invalid types.  */
  2025.  
  2026.       if (typecode != POINTER_TYPE
  2027.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  2028.     {
  2029.       if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  2030.         errstring ="wrong type argument to increment";
  2031.       else
  2032.         errstring ="wrong type argument to decrement";
  2033.       break;
  2034.     }
  2035.  
  2036.       /* Report something read-only.  */
  2037.  
  2038.       if (TREE_READONLY (arg))
  2039.     readonly_warning (arg, 
  2040.               ((code == PREINCREMENT_EXPR
  2041.                 || code == POSTINCREMENT_EXPR)
  2042.                ? "increment" : "decrement"));
  2043.  
  2044.       {
  2045.     register tree inc;
  2046.     tree result_type = TREE_TYPE (arg);
  2047.  
  2048.     arg = get_unwidened (arg, 0);
  2049.     argtype = TREE_TYPE (arg);
  2050.  
  2051.     /* Compute the increment.  */
  2052.  
  2053.     if (typecode == POINTER_TYPE)
  2054.       {
  2055.         if (pedantic && (TREE_CODE (argtype) == FUNCTION_TYPE
  2056.                  || TREE_CODE (argtype) == VOID_TYPE))
  2057.           warning ("wrong type argument to %s",
  2058.                ((code == PREINCREMENT_EXPR
  2059.              || code == POSTINCREMENT_EXPR)
  2060.             ? "increment" : "decrement"));
  2061.         inc = c_sizeof_nowarn (TREE_TYPE (argtype));
  2062.       }
  2063.     else
  2064.       inc = integer_one_node;
  2065.  
  2066.     inc = convert (argtype, inc);
  2067.  
  2068.     /* Handle incrementing a cast-expression.  */
  2069.  
  2070.     if (!pedantic)
  2071.       switch (TREE_CODE (arg))
  2072.         {
  2073.         case NOP_EXPR:
  2074.         case CONVERT_EXPR:
  2075.         case FLOAT_EXPR:
  2076.         case FIX_TRUNC_EXPR:
  2077.         case FIX_FLOOR_EXPR:
  2078.         case FIX_ROUND_EXPR:
  2079.         case FIX_CEIL_EXPR:
  2080.           {
  2081.         tree incremented, modify, value;
  2082.         arg = stabilize_reference (arg);
  2083.         if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  2084.           value = arg;
  2085.         else
  2086.           value = save_expr (arg);
  2087.         incremented = build (((code == PREINCREMENT_EXPR
  2088.                        || code == POSTINCREMENT_EXPR)
  2089.                       ? PLUS_EXPR : MINUS_EXPR),
  2090.                      argtype, value, inc);
  2091.         TREE_VOLATILE (incremented) = 1;
  2092.         modify = build_modify_expr (arg, NOP_EXPR, incremented);
  2093.         return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  2094.           }
  2095.         }
  2096.  
  2097.     /* Complain about anything else that is not a true lvalue.  */
  2098.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  2099.                     || code == POSTINCREMENT_EXPR)
  2100.                    ? "increment" : "decrement")))
  2101.       return error_mark_node;
  2102.  
  2103.     val = build (code, TREE_TYPE (arg), arg, inc);
  2104.     TREE_VOLATILE (val) = 1;
  2105.     return convert (result_type, val);
  2106.       }
  2107.  
  2108.     case ADDR_EXPR:
  2109.       /* Note that this operation never does default_conversion
  2110.      regardless of NOCONVERT.  */
  2111.  
  2112.       /* Let &* cancel out to simplify resulting code.  */
  2113.       if (TREE_CODE (arg) == INDIRECT_REF)
  2114.     return TREE_OPERAND (arg, 0);
  2115.  
  2116.       /* For &x[y], return x+y */
  2117.       if (TREE_CODE (arg) == ARRAY_REF)
  2118.     {
  2119.       mark_addressable (TREE_OPERAND (arg, 0));
  2120.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  2121.                   TREE_OPERAND (arg, 1));
  2122.     }
  2123.  
  2124.       /* Handle complex lvalues (when permitted)
  2125.      by reduction to simpler cases.  */
  2126.       val = unary_complex_lvalue (code, arg);
  2127.       if (val != 0)
  2128.     return val;
  2129.  
  2130.       /* Address of a cast is just a cast of the address
  2131.      of the operand of the cast.  */
  2132.       switch (TREE_CODE (arg))
  2133.     {
  2134.     case NOP_EXPR:
  2135.     case CONVERT_EXPR:
  2136.     case FLOAT_EXPR:
  2137.     case FIX_TRUNC_EXPR:
  2138.     case FIX_FLOOR_EXPR:
  2139.     case FIX_ROUND_EXPR:
  2140.     case FIX_CEIL_EXPR:
  2141.       if (pedantic)
  2142.         warning ("ANSI C forbids the address of a cast expression");
  2143.       return convert (build_pointer_type (TREE_TYPE (arg)),
  2144.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
  2145.                       0));
  2146.     }
  2147.  
  2148.       /* Allow the address of a constructor if all the elements
  2149.      are constant.  */
  2150.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_LITERAL (arg))
  2151.     ;
  2152.       /* Anything not already handled and not a true memory reference
  2153.      is an error.  */
  2154.       else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
  2155.     return error_mark_node;
  2156.  
  2157.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  2158.       argtype = TREE_TYPE (arg);
  2159.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  2160.     argtype = build_type_variant (argtype,
  2161.                       TREE_READONLY (arg),
  2162.                       TREE_THIS_VOLATILE (arg));
  2163.  
  2164.       argtype = build_pointer_type (argtype);
  2165.  
  2166.       mark_addressable (arg);
  2167.  
  2168.       {
  2169.     tree addr;
  2170.  
  2171.     if (TREE_CODE (arg) == COMPONENT_REF)
  2172.       {
  2173.         tree field = TREE_OPERAND (arg, 1);
  2174.  
  2175.         addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  2176.  
  2177.         if (TREE_PACKED (field))
  2178.           {
  2179.         error ("attempt to take address of bit-field structure member `%s'",
  2180.                IDENTIFIER_POINTER (DECL_NAME (field)));
  2181.         return error_mark_node;
  2182.           }
  2183.  
  2184.         if (DECL_OFFSET (field) != 0)
  2185.           {
  2186.         tree offset = build_int_2 ((DECL_OFFSET (field)
  2187.                         / BITS_PER_UNIT),
  2188.                        0);
  2189.         TREE_TYPE (offset) = argtype;
  2190.         addr = fold (build (PLUS_EXPR, argtype, addr, offset));
  2191.           }
  2192.         else
  2193.           addr = convert (argtype, addr);
  2194.       }
  2195.     else
  2196.       addr = build (code, argtype, arg);
  2197.  
  2198.     /* Address of a static or external variable or
  2199.        function counts as a constant */
  2200.     TREE_LITERAL (addr) = staticp (arg);
  2201.     return addr;
  2202.       }
  2203.     }
  2204.  
  2205.   if (!errstring)
  2206.     {
  2207.       if (argtype == 0)
  2208.     argtype = TREE_TYPE (arg);
  2209.       return fold (build (code, argtype, arg));
  2210.     }
  2211.  
  2212.   error (errstring);
  2213.   return error_mark_node;
  2214. }
  2215.  
  2216. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  2217.    convert ARG with the same conversions in the same order
  2218.    and return the result.  */
  2219.  
  2220. static tree
  2221. convert_sequence (conversions, arg)
  2222.      tree conversions;
  2223.      tree arg;
  2224. {
  2225.   switch (TREE_CODE (conversions))
  2226.     {
  2227.     case NOP_EXPR:
  2228.     case CONVERT_EXPR:
  2229.     case FLOAT_EXPR:
  2230.     case FIX_TRUNC_EXPR:
  2231.     case FIX_FLOOR_EXPR:
  2232.     case FIX_ROUND_EXPR:
  2233.     case FIX_CEIL_EXPR:
  2234.       return convert (TREE_TYPE (conversions),
  2235.               convert_sequence (TREE_OPERAND (conversions, 0),
  2236.                     arg));
  2237.  
  2238.     default:
  2239.       return arg;
  2240.     }
  2241. }
  2242.  
  2243. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  2244.    for certain kinds of expressions which are not really lvalues
  2245.    but which we can accept as lvalues.
  2246.  
  2247.    If ARG is not a kind of expression we can handle, return zero.  */
  2248.    
  2249. static tree
  2250. unary_complex_lvalue (code, arg)
  2251.      enum tree_code code;
  2252.      tree arg;
  2253. {
  2254.   if (pedantic)
  2255.     return 0;
  2256.  
  2257.   /* Handle (a, b) used as an "lvalue".  */
  2258.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  2259.     {
  2260.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  2261.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  2262.             TREE_OPERAND (arg, 0), real_result);
  2263.     }
  2264.  
  2265.   /* Handle (a ? b : c) used as an "lvalue".  */
  2266.   if (TREE_CODE (arg) == COND_EXPR)
  2267.     return (build_conditional_expr
  2268.         (TREE_OPERAND (arg, 0),
  2269.          build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  2270.          build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  2271.  
  2272.   return 0;
  2273. }
  2274.  
  2275. /* Warn about storing in something that is `const'.  */
  2276.  
  2277. void
  2278. readonly_warning (arg, string)
  2279.      tree arg;
  2280.      char *string;
  2281. {
  2282.   char buf[80];
  2283.   strcpy (buf, string);
  2284.  
  2285.   if (TREE_CODE (arg) == COMPONENT_REF)
  2286.     {
  2287.       if (TREE_READONLY (TREE_OPERAND (arg, 0)))
  2288.     readonly_warning (TREE_OPERAND (arg, 0), string);
  2289.       else
  2290.     {
  2291.       strcat (buf, " of read-only member `%s'");
  2292.       warning (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
  2293.     }
  2294.     }
  2295.   else if (TREE_CODE (arg) == VAR_DECL)
  2296.     {
  2297.       strcat (buf, " of read-only variable `%s'");
  2298.       warning (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  2299.     }
  2300.   else
  2301.     {
  2302.       warning ("%s of read-only location", buf);
  2303.     }
  2304. }
  2305.  
  2306. /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
  2307.    or validate its data type for an `if' or `while' statement or ?..: exp.
  2308.  
  2309.    This preparation consists of taking the ordinary
  2310.    representation of an expression expr and producing a valid tree
  2311.    boolean expression describing whether expr is nonzero.  We could
  2312.    simply always do build_binary_op (NE_EXPR, expr, integer_zero_node),
  2313.    but we optimize comparisons, &&, ||, and !  */
  2314.  
  2315. tree
  2316. truthvalue_conversion (expr)
  2317.      tree expr;
  2318. {
  2319.   register enum tree_code form = TREE_CODE (expr);
  2320.  
  2321.   if (form == EQ_EXPR && integer_zerop (TREE_OPERAND (expr, 1)))
  2322.     return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0);
  2323.  
  2324.   /* A one-bit unsigned bit-field is already acceptable.  */
  2325.   if (form == COMPONENT_REF
  2326.       && 1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
  2327.       && 1 == DECL_SIZE_UNIT (TREE_OPERAND (expr, 1))
  2328.       && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
  2329.     return expr;
  2330.  
  2331.   if (form == TRUTH_ANDIF_EXPR || form == TRUTH_ORIF_EXPR
  2332.       || form == TRUTH_AND_EXPR || form == TRUTH_OR_EXPR
  2333.       || form == TRUTH_NOT_EXPR
  2334.       || form == EQ_EXPR || form == NE_EXPR
  2335.       || form == LE_EXPR || form == GE_EXPR
  2336.       || form == LT_EXPR || form == GT_EXPR
  2337.       || form == ERROR_MARK)
  2338.     return expr;
  2339.  
  2340.   /* Unary minus has no effect on whether its argument is nonzero.  */
  2341.   if (form == NEGATE_EXPR)
  2342.     return truthvalue_conversion (TREE_OPERAND (expr, 0));
  2343.  
  2344.   /* Sign-extension and zero-extension has no effect.  */
  2345.   if (form == NOP_EXPR
  2346.       && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
  2347.       && (TYPE_PRECISION (TREE_TYPE (expr))
  2348.       > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))))
  2349.     return truthvalue_conversion (TREE_OPERAND (expr, 0));
  2350.  
  2351.   return build_binary_op (NE_EXPR, expr, integer_zero_node);
  2352. }
  2353.  
  2354. /* Mark EXP saying that we need to be able to take the
  2355.    address of it; it should not be allocated in a register.  */
  2356.  
  2357. static void
  2358. mark_addressable (exp)
  2359.      tree exp;
  2360. {
  2361.   register tree x = exp;
  2362.   while (1)
  2363.     switch (TREE_CODE (x))
  2364.       {
  2365.       case ADDR_EXPR:
  2366.       case COMPONENT_REF:
  2367.       case ARRAY_REF:
  2368.     x = TREE_OPERAND (x, 0);
  2369.     break;
  2370.  
  2371.       case VAR_DECL:
  2372.       case CONST_DECL:
  2373.       case PARM_DECL:
  2374.       case RESULT_DECL:
  2375.     if (TREE_REGDECL (x) && !TREE_ADDRESSABLE (x))
  2376.       warning ("address requested for `%s', which is declared `register'",
  2377.            IDENTIFIER_POINTER (DECL_NAME (x)));
  2378.     put_var_into_stack (x);
  2379.  
  2380.     /* drops in */
  2381.       case FUNCTION_DECL:
  2382.     TREE_ADDRESSABLE (x) = 1;
  2383.     TREE_ADDRESSABLE (DECL_NAME (x)) = 1;
  2384.  
  2385.       default:
  2386.     return;
  2387.     }
  2388. }
  2389.  
  2390. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  2391.  
  2392. tree
  2393. build_conditional_expr (ifexp, op1, op2)
  2394.      tree ifexp, op1, op2;
  2395. {
  2396.   register tree type1;
  2397.   register tree type2;
  2398.   register enum tree_code code1;
  2399.   register enum tree_code code2;
  2400.   register tree result_type = NULL;
  2401.  
  2402.   /* If second operand is omitted, it is the same as the first one;
  2403.      make sure it is calculated only once.  */
  2404.   if (op1 == 0)
  2405.     {
  2406.       if (pedantic)
  2407.     warning ("ANSI C forbids omitting the middle term of a ?: expression");
  2408.       ifexp = op1 = save_expr (ifexp);
  2409.     }
  2410.  
  2411.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  2412.  
  2413.   if (TREE_CODE (ifexp) == ERROR_MARK
  2414.       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
  2415.       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
  2416.     return error_mark_node;
  2417.  
  2418.   /* Don't promote the operands separately if they promote
  2419.      the same way.  Return the unpromoted type and let the combined
  2420.      value get promoted if necessary.  */
  2421.  
  2422.   if (TREE_TYPE (op1) == TREE_TYPE (op2)
  2423.       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
  2424.       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
  2425.       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
  2426.     {
  2427.       if (TREE_LITERAL (ifexp)
  2428.       && (TREE_CODE (ifexp) == INTEGER_CST
  2429.           || TREE_CODE (ifexp) == ADDR_EXPR))
  2430.     return (integer_zerop (ifexp) ? op2 : op1);
  2431.  
  2432.       return build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2);
  2433.     }
  2434.  
  2435.   /* They don't match; promote them both and then try to reconcile them.  */
  2436.  
  2437.   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
  2438.     op1 = default_conversion (op1);
  2439.   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
  2440.     op2 = default_conversion (op2);
  2441.  
  2442.   type1 = TREE_TYPE (op1);
  2443.   code1 = TREE_CODE (type1);
  2444.   type2 = TREE_TYPE (op2);
  2445.   code2 = TREE_CODE (type2);
  2446.       
  2447.   /* Quickly detect the usual case where op1 and op2 have the same type
  2448.      after promotion.  */
  2449.   if (type1 == type2)
  2450.     result_type = type1;
  2451.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  2452.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  2453.     {
  2454.       result_type = commontype (type1, type2);
  2455.     }
  2456.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  2457.     {
  2458.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  2459.     warning ("ANSI C forbids conditional expr with only one void side");
  2460.       result_type = void_type_node;
  2461.     }
  2462.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  2463.     {
  2464.       if (comp_target_types (type1, type2))
  2465.     result_type = commontype (type1, type2);
  2466.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  2467.     {
  2468.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  2469.         warning ("ANSI C forbids conditional expr between `void *' and function pointer");
  2470.       result_type = qualify_type (type1, type2);
  2471.     }
  2472.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  2473.     {
  2474.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  2475.         warning ("ANSI C forbids conditional expr between `void *' and function pointer");
  2476.       result_type = qualify_type (type2, type1);
  2477.     }
  2478.       else
  2479.     {
  2480.       warning ("pointer type mismatch in conditional expression");
  2481.       result_type = build_pointer_type (void_type_node);
  2482.     }
  2483.     }
  2484.   else if (code1 == POINTER_TYPE && TREE_CODE (op2) == INTEGER_CST)
  2485.     {
  2486.       if (!integer_zerop (op2))
  2487.     warning ("pointer/integer type mismatch in conditional expression");
  2488.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  2489.     warning ("ANSI C forbids conditional expr between 0 and function pointer");
  2490.       result_type = type1;
  2491.       op2 = null_pointer_node;
  2492.     }
  2493.   else if (code2 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST)
  2494.     {
  2495.       if (!integer_zerop (op1))
  2496.     warning ("pointer/integer type mismatch in conditional expression");
  2497.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  2498.     warning ("ANSI C forbids conditional expr between 0 and function pointer");
  2499.       result_type = type2;
  2500.       op1 = null_pointer_node;
  2501.     }
  2502.  
  2503.   if (!result_type)
  2504.     {
  2505.       if (flag_cond_mismatch)
  2506.     result_type = void_type_node;
  2507.       else
  2508.     {
  2509.       error ("type mismatch in conditional expression");
  2510.       return error_mark_node;
  2511.     }
  2512.     }
  2513.  
  2514.   if (result_type != TREE_TYPE (op1))
  2515.     op1 = convert (result_type, op1);
  2516.   if (result_type != TREE_TYPE (op2))
  2517.     op2 = convert (result_type, op2);
  2518.     
  2519. #if 0
  2520.   if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
  2521.     {
  2522.       result_type = TREE_TYPE (op1);
  2523.       if (TREE_LITERAL (ifexp))
  2524.     return (integer_zerop (ifexp) ? op2 : op1);
  2525.  
  2526.       if (TYPE_MODE (result_type) == BLKmode)
  2527.     {
  2528.       register tree tempvar
  2529.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  2530.       register tree xop1 = build_modify_expr (tempvar, op1);
  2531.       register tree xop2 = build_modify_expr (tempvar, op2);
  2532.       register tree result = build (COND_EXPR, result_type,
  2533.                     ifexp, xop1, xop2);
  2534.  
  2535.       layout_decl (tempvar);
  2536.       /* No way to handle variable-sized objects here.
  2537.          I fear that the entire handling of BLKmode conditional exprs
  2538.          needs to be redone.  */
  2539.       if (! TREE_LITERAL (DECL_SIZE (tempvar)))
  2540.         abort ();
  2541.       DECL_RTL (tempvar)
  2542.         = assign_stack_local (DECL_MODE (tempvar),
  2543.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  2544.                    * DECL_SIZE_UNIT (tempvar)
  2545.                    + BITS_PER_UNIT - 1)
  2546.                   / BITS_PER_UNIT);
  2547.  
  2548.       TREE_VOLATILE (result)
  2549.         = TREE_VOLATILE (ifexp) | TREE_VOLATILE (op1)
  2550.           | TREE_VOLATILE (op2);
  2551.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  2552.     }
  2553.     }
  2554. #endif /* 0 */
  2555.  
  2556.   if (TREE_LITERAL (ifexp))
  2557.     return (integer_zerop (ifexp) ? op2 : op1);
  2558.  
  2559.   return build (COND_EXPR, result_type, ifexp, op1, op2);
  2560. }
  2561.  
  2562. /* Given a list of expressions, return a compound expression
  2563.    that performs them all and returns the value of the last of them.  */
  2564.  
  2565. tree
  2566. build_compound_expr (list)
  2567.      tree list;
  2568. {
  2569.   register tree rest;
  2570.  
  2571.   if (TREE_CHAIN (list) == 0)
  2572.     return TREE_VALUE (list);
  2573.  
  2574.   rest = build_compound_expr (TREE_CHAIN (list));
  2575.  
  2576.   if (! TREE_VOLATILE (TREE_VALUE (list)))
  2577.     return rest;
  2578.  
  2579.   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
  2580. }
  2581.  
  2582. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  2583.  
  2584. tree
  2585. build_c_cast (type, expr)
  2586.      register tree type;
  2587.      tree expr;
  2588. {
  2589.   register tree value;
  2590.   
  2591.   if (type == error_mark_node)
  2592.     return error_mark_node;
  2593.  
  2594.   if (type == TREE_TYPE (expr))
  2595.     {
  2596.       if (pedantic)
  2597.     {
  2598.       if (TREE_CODE (type) == RECORD_TYPE
  2599.           || TREE_CODE (type) == UNION_TYPE)
  2600.         warning ("ANSI C forbids casting nonscalar to the same type");
  2601.     }
  2602.       return expr;
  2603.     }
  2604.  
  2605.   value = convert (TYPE_MAIN_VARIANT (type), default_conversion (expr));
  2606.   /* As far as I know, it is not meaningful to cast something
  2607.      to a const or volatile type, because those are meaningful
  2608.      only for lvalues.
  2609.      But if it is meaningful, we must somehow return something
  2610.      whose TREE_READONLY or TREE_VOLATILE is set.
  2611.      That is not trivial because it is possible that VALUE == EXPR
  2612.      or is a shared constant.  */
  2613.   return value;
  2614. }
  2615.  
  2616. /* Build an assignment expression of lvalue LHS from value RHS.
  2617.    MODIFYCODE is the code for a binary operator that we use
  2618.    to combine the old value of LHS with RHS to get the new value.
  2619.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
  2620.  
  2621. tree
  2622. build_modify_expr (lhs, modifycode, rhs)
  2623.      tree lhs, rhs;
  2624.      enum tree_code modifycode;
  2625. {
  2626.   register tree result;
  2627.   tree newrhs = rhs;
  2628.   tree lhstype = TREE_TYPE (lhs);
  2629.   tree olhstype = lhstype;
  2630.  
  2631.   /* Types that aren't fully specified cannot be used in assignments.  */
  2632.   lhs = require_complete_type (lhs);
  2633.  
  2634.   /* Avoid duplicate error messages from operands that had errors.  */
  2635.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  2636.     return error_mark_node;
  2637.  
  2638.   /* Handle control structure constructs used as "lvalues".  */
  2639.  
  2640.   if (!pedantic)
  2641.     switch (TREE_CODE (lhs))
  2642.       {
  2643.     /* Handle (a, b) used as an "lvalue".  */
  2644.       case COMPOUND_EXPR:
  2645.     return build (COMPOUND_EXPR, lhstype,
  2646.               TREE_OPERAND (lhs, 0),
  2647.               build_modify_expr (TREE_OPERAND (lhs, 1),
  2648.                      modifycode, rhs));
  2649.  
  2650.     /* Handle (a ? b : c) used as an "lvalue".  */
  2651.       case COND_EXPR:
  2652.     rhs = save_expr (rhs);
  2653.     return (build_conditional_expr
  2654.         (TREE_OPERAND (lhs, 0),
  2655.          build_modify_expr (TREE_OPERAND (lhs, 1), modifycode, rhs),
  2656.          build_modify_expr (TREE_OPERAND (lhs, 2), modifycode, rhs)));
  2657.       }
  2658.  
  2659.   /* If a binary op has been requested, combine the old LHS value with the RHS
  2660.      producing the value we should actually store into the LHS.  */
  2661.  
  2662.   if (modifycode != NOP_EXPR)
  2663.     {
  2664.       lhs = stabilize_reference (lhs);
  2665.       newrhs = build_binary_op (modifycode, lhs, rhs);
  2666.     }
  2667.  
  2668.   /* Handle a cast used as an "lvalue".
  2669.      We have already performed any binary operator using the value as cast.
  2670.      Now convert the result to the true type of the lhs and store there;
  2671.      then cast the result back to the specified type to be the value
  2672.      of the assignment.  */
  2673.  
  2674.   if (!pedantic)
  2675.     switch (TREE_CODE (lhs))
  2676.       {
  2677.       case NOP_EXPR:
  2678.       case CONVERT_EXPR:
  2679.       case FLOAT_EXPR:
  2680.       case FIX_TRUNC_EXPR:
  2681.       case FIX_FLOOR_EXPR:
  2682.       case FIX_ROUND_EXPR:
  2683.       case FIX_CEIL_EXPR:
  2684.     if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  2685.         || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
  2686.       newrhs = default_conversion (newrhs);
  2687.     {
  2688.       tree inner_lhs = TREE_OPERAND (lhs, 0);
  2689.       tree result = build_modify_expr (inner_lhs, NOP_EXPR,
  2690.                        convert (TREE_TYPE (inner_lhs),
  2691.                             newrhs));
  2692.       return convert (TREE_TYPE (lhs), result);
  2693.     }
  2694.       }
  2695.  
  2696.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  2697.      Reject anything strange now.  */
  2698.  
  2699.   if (!lvalue_or_else (lhs, "assignment"))
  2700.     return error_mark_node;
  2701.  
  2702.   /* Warn about storing in something that is `const'.  */
  2703.  
  2704.   if (TREE_READONLY (lhs)
  2705.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  2706.        || TREE_CODE (lhstype) == UNION_TYPE)
  2707.       && C_TYPE_FIELDS_READONLY (lhstype)))
  2708.     readonly_warning (lhs, "assignment");
  2709.  
  2710.   /* If storing into a structure or union member,
  2711.      it has probably been given type `int'.
  2712.      Compute the type that would go with
  2713.      the actual amount of storage the member occupies.  */
  2714.  
  2715.   if (TREE_CODE (lhs) == COMPONENT_REF
  2716.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  2717.       || TREE_CODE (lhstype) == REAL_TYPE
  2718.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  2719.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  2720.  
  2721.   /* If storing in a field that is in actuality a short or narrower than one,
  2722.      we must store in the field in its actual type.  */
  2723.  
  2724.   if (lhstype != TREE_TYPE (lhs))
  2725.     {
  2726.       lhs = copy_node (lhs);
  2727.       TREE_TYPE (lhs) = lhstype;
  2728.     }
  2729.  
  2730.   /* Convert new value to destination type.  */
  2731.  
  2732.   newrhs = convert_for_assignment (lhstype, newrhs, "assignment");
  2733.  
  2734.   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
  2735.   TREE_VOLATILE (result) = 1;
  2736.  
  2737.   /* If we got the LHS in a different type for storing in,
  2738.      convert the result back to the nominal type of LHS
  2739.      so that the value we return always has the same type
  2740.      as the LHS argument.  */
  2741.  
  2742.   if (olhstype == TREE_TYPE (result))
  2743.     return result;
  2744.   return convert_for_assignment (olhstype, result, "assignment");
  2745. }
  2746.  
  2747. /* Return 0 if EXP is not a valid lvalue in this language
  2748.    even though `lvalue_or_else' would accept it.  */
  2749.  
  2750. int
  2751. language_lvalue_valid (exp)
  2752.      tree exp;
  2753. {
  2754.   return 1;
  2755. }
  2756.  
  2757. /* Convert value RHS to type TYPE as preparation for an assignment
  2758.    to an lvalue of type TYPE.
  2759.    The real work of conversion is done by `convert'.
  2760.    The purpose of this function is to generate error messages
  2761.    for assignments that are not allowed in C.
  2762.    ERRTYPE is a string to use in error messages:
  2763.    "assignment", "return", etc.  */
  2764.  
  2765. static tree
  2766. convert_for_assignment (type, rhs, errtype)
  2767.      tree type, rhs;
  2768.      char *errtype;
  2769. {
  2770.   register enum tree_code codel = TREE_CODE (type);
  2771.   register tree rhstype = datatype (rhs);
  2772.   register enum tree_code coder = TREE_CODE (rhstype);
  2773.  
  2774.   if (coder == ERROR_MARK)
  2775.     return rhs;
  2776.  
  2777.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  2778.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
  2779.     rhs = default_conversion (rhs);
  2780.  
  2781.   if (type == rhstype)
  2782.     return rhs;
  2783.  
  2784.   if (coder == VOID_TYPE)
  2785.     {
  2786.       error ("void value not ignored as it ought to be");
  2787.       return error_mark_node;
  2788.     }
  2789.   /* Arithmetic types all interconvert, and enum is treated like int.  */
  2790.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE)
  2791.        &&
  2792.       (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE))
  2793.     {
  2794.       return convert (type, rhs);
  2795.     }
  2796.   /* Conversions among pointers */
  2797.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  2798.     {
  2799.       register tree ttl = TREE_TYPE (type);
  2800.       register tree ttr = TREE_TYPE (rhstype);
  2801.       /* Any non-function converts to a [const][volatile] void *
  2802.      and vice versa; otherwise, targets must be the same.
  2803.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  2804.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  2805.       || TYPE_MAIN_VARIANT (ttr) == void_type_node
  2806.       || comp_target_types (type, rhstype))
  2807.     {
  2808.       if (pedantic
  2809.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  2810.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  2811.           ||
  2812.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  2813.            && TREE_CODE (ttl) == FUNCTION_TYPE)))
  2814.         warning ("%s between incompatible pointer types", errtype);
  2815.       else
  2816.         {
  2817.           if (! TREE_READONLY (ttl) && TREE_READONLY (ttr))
  2818.         warning ("%s of non-const * pointer from const *", errtype);
  2819.           if (! TREE_VOLATILE (ttl) && TREE_VOLATILE (ttr))
  2820.         warning ("%s of non-volatile * pointer from volatile *", errtype);
  2821.         }
  2822.     }
  2823.       else
  2824.     warning ("%s between incompatible pointer types", errtype);
  2825.       return convert (type, rhs);
  2826.     }
  2827.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  2828.     {
  2829.       if (! integer_zerop (rhs))
  2830.     {
  2831.       warning ("%s of pointer from integer lacks a cast", errtype);
  2832.       return convert (type, rhs);
  2833.     }
  2834.       return null_pointer_node;
  2835.     }
  2836.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  2837.     {
  2838.       warning ("%s of integer from pointer lacks a cast", errtype);
  2839.       return convert (type, rhs);
  2840.     }
  2841.  
  2842.   error ("incompatible types in %s", errtype);
  2843.   return error_mark_node;
  2844. }
  2845.  
  2846. /* Return nonzero if VALUE is a valid constant-valued expression
  2847.    for use in initializing a static variable; one that can be an
  2848.    element of a "constant" initializer.
  2849.  
  2850.    Return 1 if the value is absolute; return 2 if it is relocatable.
  2851.    We assume that VALUE has been folded as much as possible;
  2852.    therefore, we do not need to check for such things as
  2853.    arithmetic-combinations of integers.  */
  2854.  
  2855. static int
  2856. initializer_constant_valid_p (value)
  2857.      tree value;
  2858. {
  2859.   switch (TREE_CODE (value))
  2860.     {
  2861.     case CONSTRUCTOR:
  2862.       return TREE_STATIC (value);
  2863.  
  2864.     case INTEGER_CST:
  2865.     case REAL_CST:
  2866.     case STRING_CST:
  2867.       return 1;
  2868.  
  2869.     case ADDR_EXPR:
  2870.       return 2;
  2871.  
  2872.     case CONVERT_EXPR:
  2873.       /* Allow (int) &foo.  */
  2874.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  2875.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
  2876.     return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2877.       return 0;
  2878.     
  2879.     case NOP_EXPR:
  2880.       return initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2881.  
  2882.     case PLUS_EXPR:
  2883.       {
  2884.     int valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2885.     int valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  2886.     if (valid0 == 1 && valid1 == 2)
  2887.       return 2;
  2888.     if (valid0 == 2 && valid1 == 1)
  2889.       return 2;
  2890.     return 0;
  2891.       }
  2892.  
  2893.     case MINUS_EXPR:
  2894.       {
  2895.     int valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0));
  2896.     int valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1));
  2897.     if (valid0 == 2 && valid1 == 1)
  2898.       return 2;
  2899.     return 0;
  2900.       }
  2901.     }
  2902.  
  2903.   return 0;
  2904. }
  2905.  
  2906. /* Perform appropriate conversions on the initial value of a variable,
  2907.    store it in the declaration DECL,
  2908.    and print any error messages that are appropriate.
  2909.    If the init is invalid, store an ERROR_MARK.  */
  2910.  
  2911. void
  2912. store_init_value (decl, init)
  2913.      tree decl, init;
  2914. {
  2915.   register tree value, type;
  2916.  
  2917.   /* If variable's type was invalidly declared, just ignore it.  */
  2918.  
  2919.   type = TREE_TYPE (decl);
  2920.   if (TREE_CODE (type) == ERROR_MARK)
  2921.     return;
  2922.  
  2923.   /* Digest the specified initializer into an expression.  */
  2924.  
  2925.   value = digest_init (type, init, 0);
  2926.  
  2927.   /* Store the expression if valid; else report error.  */
  2928.  
  2929.   if (value == error_mark_node)
  2930.     ;
  2931.   else if (TREE_STATIC (decl) && ! TREE_LITERAL (value))
  2932.     {
  2933.       error ("initializer for static variable is not constant");
  2934.       value = error_mark_node;
  2935.     }
  2936.   else if (TREE_STATIC (decl)
  2937.        && ! initializer_constant_valid_p (value))
  2938.     {
  2939.       error ("initializer for static variable uses complex arithmetic");
  2940.       value = error_mark_node;
  2941.     }
  2942.   else
  2943.     {
  2944.       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
  2945.     {
  2946.       if (! TREE_LITERAL (value))
  2947.         warning ("aggregate initializer is not constant");
  2948.       else if (! TREE_STATIC (value))
  2949.         warning ("aggregate initializer uses complex arithmetic");
  2950.     }
  2951.     }
  2952.   DECL_INITIAL (decl) = value;
  2953. }
  2954.  
  2955. /* Digest the parser output INIT as an initializer for type TYPE.
  2956.    Return a C expression of type TYPE to represent the initial value.
  2957.  
  2958.    If TAIL is nonzero, it points to a variable holding a list of elements
  2959.    of which INIT is the first.  We update the list stored there by
  2960.    removing from the head all the elements that we use.
  2961.    Normally this is only one; we use more than one element only if
  2962.    TYPE is an aggregate and INIT is not a constructor.  */
  2963.  
  2964. tree
  2965. digest_init (type, init, tail)
  2966.      tree type, init, *tail;
  2967. {
  2968.   enum tree_code code = TREE_CODE (type);
  2969.   tree element = 0;
  2970.   tree old_tail_contents;
  2971.   /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
  2972.      tree node which has no TREE_TYPE.  */
  2973.   int raw_constructor
  2974.     = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;
  2975.  
  2976.   /* By default, assume we use one element from a list.
  2977.      We correct this later in the sole case where it is not true.  */
  2978.  
  2979.   if (tail)
  2980.     {
  2981.       old_tail_contents = *tail;
  2982.       *tail = TREE_CHAIN (*tail);
  2983.     }
  2984.  
  2985.   if (init == error_mark_node)
  2986.     return init;
  2987.  
  2988.   if (init && raw_constructor
  2989.       && CONSTRUCTOR_ELTS (init) != 0
  2990.       && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
  2991.     element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
  2992.  
  2993.   /* Any type can be initialized from an expression of the same type,
  2994.      optionally with braces.  */
  2995.  
  2996.   if (init && (TREE_TYPE (init) == type
  2997.            || (code == ARRAY_TYPE && TREE_TYPE (init)
  2998.            && comptypes (TREE_TYPE (init), type))))
  2999.     {
  3000.       if (pedantic && code == ARRAY_TYPE
  3001.       && TREE_CODE (init) != STRING_CST)
  3002.     warning ("ANSI C forbids initializing array from array expression");
  3003.       return init;
  3004.     }
  3005.  
  3006.   if (element && (TREE_TYPE (element) == type
  3007.           || (code == ARRAY_TYPE && TREE_TYPE (element)
  3008.               && comptypes (TREE_TYPE (element), type))))
  3009.     {
  3010.       if (pedantic && code == ARRAY_TYPE)
  3011.     warning ("ANSI C forbids initializing array from array expression");
  3012.       if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
  3013.     warning ("single-expression nonscalar initializer has braces");
  3014.       return element;
  3015.     }
  3016.  
  3017.   /* Check for initializing a union by its first field.
  3018.      Such an initializer must use braces.  */
  3019.  
  3020.   if (code == UNION_TYPE)
  3021.     {
  3022.       tree result;
  3023.  
  3024.       if (TYPE_FIELDS (type) == 0)
  3025.     {
  3026.       error ("union with no members cannot be initialized");
  3027.       return error_mark_node;
  3028.     }
  3029.       if (! raw_constructor)
  3030.     {
  3031.       error ("type mismatch in initialization");
  3032.       return error_mark_node;
  3033.     }
  3034.       if (element == 0)
  3035.     {
  3036.       error ("union initializer requires one element");
  3037.       return error_mark_node;
  3038.     }
  3039.       /* Take just the first element from within the constructor
  3040.      and it should match the type of the first element.  */
  3041.       element = digest_init (TREE_TYPE (TYPE_FIELDS (type)), element, 0);
  3042.       result = build (CONSTRUCTOR, type, 0, build_tree_list (0, element));
  3043.       TREE_LITERAL (result) = TREE_LITERAL (element);
  3044.       TREE_STATIC (result) = (initializer_constant_valid_p (element)
  3045.                   && TREE_LITERAL (element));
  3046.       return result;
  3047.     }
  3048.  
  3049.   /* Initialization of an array of chars from a string constant
  3050.      optionally enclosed in braces.  */
  3051.  
  3052.   if (code == ARRAY_TYPE
  3053.       && (TREE_TYPE (type) == char_type_node
  3054.       || TREE_TYPE (type) == signed_char_type_node
  3055.       || TREE_TYPE (type) == unsigned_char_type_node
  3056.       || TREE_TYPE (type) == unsigned_type_node
  3057.       || TREE_TYPE (type) == integer_type_node)
  3058.       && ((init && TREE_CODE (init) == STRING_CST)
  3059.       || (element && TREE_CODE (element) == STRING_CST)))
  3060.     {
  3061.       tree string = element ? element : init;
  3062.  
  3063.       if (TREE_TYPE (TREE_TYPE (string)) != char_type_node
  3064.       && TYPE_PRECISION (TREE_TYPE (type)) == BITS_PER_UNIT)
  3065.     {
  3066.       error ("char-array initialized from wide string");
  3067.       return error_mark_node;
  3068.     }
  3069.       if (TREE_TYPE (TREE_TYPE (string)) == char_type_node
  3070.       && TYPE_PRECISION (TREE_TYPE (type)) != BITS_PER_UNIT)
  3071.     {
  3072.       error ("int-array initialized from non-wide string");
  3073.       return error_mark_node;
  3074.     }
  3075.  
  3076.       if (pedantic && TREE_TYPE (type) != char_type_node)
  3077.     warning ("ANSI C forbids string initializer except for `char' elements");
  3078.       TREE_TYPE (string) = type;
  3079.       if (TYPE_DOMAIN (type) != 0
  3080.       && TREE_LITERAL (TYPE_SIZE (type)))
  3081.     {
  3082.       register int size
  3083.         = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
  3084.       size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  3085.       /* Subtract 1 because it's ok to ignore the terminating null char
  3086.          that is counted in the length of the constant.  */
  3087.       if (size < TREE_STRING_LENGTH (string) - 1)
  3088.         warning ("initializer-string for array of chars is too long");
  3089.     }
  3090.       return string;
  3091.     }
  3092.  
  3093.   /* Handle scalar types, including conversions.  */
  3094.  
  3095.   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
  3096.       || code == ENUMERAL_TYPE)
  3097.     {
  3098.       if (raw_constructor)
  3099.     {
  3100.       if (element == 0)
  3101.         {
  3102.           error ("initializer for scalar variable requires one element");
  3103.           return error_mark_node;
  3104.         }
  3105.       init = element;
  3106.     }
  3107.  
  3108.       return convert_for_assignment (type, default_conversion (init),
  3109.                      "initialization");
  3110.     }
  3111.  
  3112.   /* Come here only for records and arrays.  */
  3113.  
  3114.   if (TYPE_SIZE (type) && ! TREE_LITERAL (TYPE_SIZE (type)))
  3115.     {
  3116.       error ("variable-sized object may not be initialized");
  3117.       return error_mark_node;
  3118.     }
  3119.  
  3120.   if (code == ARRAY_TYPE || code == RECORD_TYPE)
  3121.     {
  3122.       tree result = 0;
  3123.       if (raw_constructor)
  3124.     return process_init_constructor (type, init, 0);
  3125.       else if (tail != 0)
  3126.     {
  3127.       *tail = old_tail_contents;
  3128.       return process_init_constructor (type, 0, tail);
  3129.     }
  3130.       else if (flag_traditional)
  3131.     /* Traditionally one can say `char x[100] = 0;'.  */
  3132.     return process_init_constructor (type,
  3133.                      build_nt (CONSTRUCTOR, 0,
  3134.                            tree_cons (0, init, 0)),
  3135.                      0);
  3136.     }
  3137.  
  3138.   error ("invalid initializer");
  3139.   return error_mark_node;
  3140. }
  3141.  
  3142. /* Process a constructor for a variable of type TYPE.
  3143.    The constructor elements may be specified either with INIT or with ELTS,
  3144.    only one of which should be non-null.
  3145.  
  3146.    If INIT is specified, it is a CONSTRUCTOR node which is specifically
  3147.    and solely for initializing this datum.
  3148.  
  3149.    If ELTS is specified, it is the address of a variable containing
  3150.    a list of expressions.  We take as many elements as we need
  3151.    from the head of the list and update the list.
  3152.  
  3153.    In the resulting constructor, TREE_LITERAL is set if all elts are
  3154.    constant, and TREE_STATIC is set if, in addition, all elts are simple enough
  3155.    constants that the assembler and linker can compute them.  */
  3156.  
  3157. static tree
  3158. process_init_constructor (type, init, elts)
  3159.      tree type, init, *elts;
  3160. {
  3161.   register tree tail;
  3162.   /* List of the elements of the result constructor,
  3163.      in reverse order.  */
  3164.   register tree members = NULL;
  3165.   tree result;
  3166.   int allconstant = 1;
  3167.   int allsimple = 1;
  3168.   int error = 0;
  3169.  
  3170.   /* Make TAIL be the list of elements to use for the initialization,
  3171.      no matter how the data was given to us.  */
  3172.  
  3173.   if (elts)
  3174.     tail = *elts;
  3175.   else
  3176.     tail = CONSTRUCTOR_ELTS (init);
  3177.  
  3178.   /* Gobble as many elements as needed, and make a constructor or initial value
  3179.      for each element of this aggregate.  Chain them together in result.
  3180.      If there are too few, use 0 for each scalar ultimate component.  */
  3181.  
  3182.   if (TREE_CODE (type) == ARRAY_TYPE)
  3183.     {
  3184.       tree domain = TYPE_DOMAIN (type);
  3185.       register long len;
  3186.       register int i;
  3187.  
  3188.       if (domain)
  3189.     len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
  3190.       - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
  3191.         + 1;
  3192.       else
  3193.     len = -1;  /* Take as many as there are */
  3194.  
  3195.       for (i = 0; (len < 0 || i < len) && tail != 0; i++)
  3196.     {
  3197.       register tree next1;
  3198.  
  3199.       if (TREE_VALUE (tail) != 0)
  3200.         {
  3201.           tree tail1 = tail;
  3202.           next1 = digest_init (TREE_TYPE (type),
  3203.                    TREE_VALUE (tail), &tail1);
  3204.           tail = tail1;
  3205.         }
  3206.       else
  3207.         {
  3208.           next1 = error_mark_node;
  3209.           tail = TREE_CHAIN (tail);
  3210.         }
  3211.  
  3212.       if (next1 == error_mark_node)
  3213.         error = 1;
  3214.       else if (!TREE_LITERAL (next1))
  3215.         allconstant = 0;
  3216.       else if (! initializer_constant_valid_p (next1))
  3217.         allsimple = 0;
  3218.       members = tree_cons (NULL_TREE, next1, members);
  3219.     }
  3220.     }
  3221.   if (TREE_CODE (type) == RECORD_TYPE)
  3222.     {
  3223.       register tree field;
  3224.  
  3225.       for (field = TYPE_FIELDS (type); field && tail;
  3226.        field = TREE_CHAIN (field))
  3227.     {
  3228.       register tree next1;
  3229.  
  3230.       if (TREE_VALUE (tail) != 0)
  3231.         {
  3232.           tree tail1 = tail;
  3233.           next1 = digest_init (TREE_TYPE (field),
  3234.                    TREE_VALUE (tail), &tail1);
  3235.           tail = tail1;
  3236.         }
  3237.       else
  3238.         {
  3239.           next1 = error_mark_node;
  3240.           tail = TREE_CHAIN (tail);
  3241.         }
  3242.  
  3243.       if (next1 == error_mark_node)
  3244.         error = 1;
  3245.       else if (!TREE_LITERAL (next1))
  3246.         allconstant = 0;
  3247.       else if (! initializer_constant_valid_p (next1))
  3248.         allsimple = 0;
  3249.       members = tree_cons (field, next1, members);
  3250.     }
  3251.     }
  3252.  
  3253.   /* If arguments were specified as a list, just remove the ones we used.  */
  3254.   if (elts)
  3255.     *elts = tail;
  3256.   /* If arguments were specified as a constructor,
  3257.      complain unless we used all the elements of the constructor.  */
  3258.   else if (tail)
  3259.     warning ("excess elements in aggregate initializer");
  3260.  
  3261.   if (error)
  3262.     return error_mark_node;
  3263.  
  3264.   result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
  3265.   if (allconstant) TREE_LITERAL (result) = 1;
  3266.   if (allconstant && allsimple) TREE_STATIC (result) = 1;
  3267.   return result;
  3268. }
  3269.  
  3270. /* Expand an ASM statement with operands, handling output operands
  3271.    that are not variables or INDIRECT_REFS by transforming such
  3272.    cases into cases that expand_asm_operands can handle.
  3273.  
  3274.    Arguments are same as for expand_asm_operands.  */
  3275.  
  3276. void
  3277. c_expand_asm_operands (string, outputs, inputs, vol)
  3278.      tree string, outputs, inputs;
  3279.      int vol;
  3280. {
  3281.   int noutputs = list_length (outputs);
  3282.   register int i;
  3283.   /* o[I] is the place that output number I should be written.  */
  3284.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  3285.   register tree tail;
  3286.  
  3287.   /* Record the contents of OUTPUTS before it is modifed.  */
  3288.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  3289.     o[i] = TREE_VALUE (tail);
  3290.  
  3291.   /* Generate the ASM_OPERANDS insn;
  3292.      store into the TREE_VALUEs of OUTPUTS some trees for
  3293.      where the values were actually stored.  */
  3294.   expand_asm_operands (string, outputs, inputs, vol);
  3295.  
  3296.   /* Copy all the intermediate outputs into the specified outputs.  */
  3297.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  3298.     if (o[i] != TREE_VALUE (tail))
  3299.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  3300.            0, VOIDmode, 0);
  3301. }
  3302.  
  3303. /* Expand a C `return' statement.
  3304.    RETVAL is the expression for what to return,
  3305.    or a null pointer for `return;' with no value.  */
  3306.  
  3307. void
  3308. c_expand_return (retval)
  3309.      tree retval;
  3310. {
  3311.   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
  3312.  
  3313.   if (!retval)
  3314.     {
  3315.       current_function_returns_null = 1;
  3316.       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
  3317.     warning ("`return' with no value, in function returning non-void");
  3318.       expand_null_return ();
  3319.     }
  3320.   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
  3321.     {
  3322.       current_function_returns_null = 1;
  3323.       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  3324.     warning ("`return' with a value, in function returning void");
  3325.       expand_return (retval);
  3326.     }
  3327.   else
  3328.     {
  3329.       tree t = convert_for_assignment (valtype, retval, "return");
  3330.       tree res = DECL_RESULT (current_function_decl);
  3331.       t = build (MODIFY_EXPR, TREE_TYPE (res),
  3332.          res, convert (TREE_TYPE (res), t));
  3333.       expand_return (t);
  3334.       current_function_returns_value = 1;
  3335.     }
  3336. }
  3337.  
  3338. /* Start a C switch statement, testing expression EXP.
  3339.    Return EXP if it is valid, an error node otherwise.  */
  3340.  
  3341. tree
  3342. c_expand_start_case (exp)
  3343.      tree exp;
  3344. {
  3345.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  3346.   tree type = TREE_TYPE (exp);
  3347.  
  3348.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  3349.     {
  3350.       error ("switch quantity not an integer");
  3351.       exp = error_mark_node;
  3352.     }
  3353.   else
  3354.     {
  3355.       tree index;
  3356.  
  3357.       exp = default_conversion (exp);
  3358.       type = TREE_TYPE (exp);
  3359.       index = get_unwidened (exp, 0);
  3360.       /* We can't strip a conversion from a signed type to an unsigned,
  3361.      because if we did, int_fits_type_p would do the wrong thing
  3362.      when checking case values for being in range,
  3363.      and it's too hard to do the right thing.  */
  3364.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  3365.       == TREE_UNSIGNED (TREE_TYPE (index)))
  3366.     exp = index;
  3367.     }
  3368.  
  3369.   expand_start_case (1, exp, type);
  3370.  
  3371.   return exp;
  3372. }
  3373.